7 kyu
The 'spiraling' box
775 of 1,795brodiemark
Description:
Task
Given two positive integers m (width)
and n (height)
, fill a two-dimensional list (or array) of size m-by-n
in the following way:
(1) All the elements in the first and last row and column are 1.
(2) All the elements in the second and second-last row and column are 2, excluding the elements from step 1.
(3) All the elements in the third and third-last row and column are 3, excluding the elements from the previous steps.
And so on ...
Examples
Given m = 5, n = 8, your function should return
[[1, 1, 1, 1, 1],
[1, 2, 2, 2, 1],
[1, 2, 3, 2, 1],
[1, 2, 3, 2, 1],
[1, 2, 3, 2, 1],
[1, 2, 3, 2, 1],
[1, 2, 2, 2, 1],
[1, 1, 1, 1, 1]]
Given m = 10, n = 9, your function should return
[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[1, 2, 3, 3, 3, 3, 3, 3, 2, 1],
[1, 2, 3, 4, 4, 4, 4, 3, 2, 1],
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1],
[1, 2, 3, 4, 4, 4, 4, 3, 2, 1],
[1, 2, 3, 3, 3, 3, 3, 3, 2, 1],
[1, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
Bird mountain generalizes this kata in a fun way.
Arrays
Fundamentals
Similar Kata:
Stats:
Created | Jan 6, 2023 |
Published | Jan 6, 2023 |
Warriors Trained | 6779 |
Total Skips | 224 |
Total Code Submissions | 6538 |
Total Times Completed | 1795 |
Python Completions | 775 |
C Completions | 114 |
Java Completions | 276 |
C# Completions | 143 |
Swift Completions | 90 |
Go Completions | 116 |
Kotlin Completions | 87 |
Rust Completions | 51 |
JavaScript Completions | 198 |
C++ Completions | 48 |
Haskell Completions | 10 |
Total Stars | 130 |
% of votes with a positive feedback rating | 91% of 274 |
Total "Very Satisfied" Votes | 233 |
Total "Somewhat Satisfied" Votes | 30 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 12 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |