CodePark/ problems / Count Down List
START PRACTICINGPRACTICE
Coding problem · Data structures and algorithms › Foundations

Count Down List

easyabout 8 minutes in an interview

Write countDown(n) that returns the array [n, n - 1, …, 2, 1].

  • n is a whole number from 0 to 1000.
  • countDown(0) returns an empty array [].
  • Solve it without loops: no for, while, .map, Array.from and so on. Instead, countDown should build its answer from countDown of a smaller number.
Input: n = 3 Output: [3, 2, 1]
Input: n = 1 Output: [1]
Input: n = 0 Output: []