FastPrepNumbers from One to N without Loops
Problems/Numbers from One to N without Loops

Numbers from One to N without Loops

AMD logoAMD● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report requests printing 1 through 100 in C without loops. The n parameter, returned array, zero case and five-language implementations are authored for practice; approximate source match 90%.

Return [1,2,...,n] using recursion rather than an explicit for or while loop. For zero, return an empty array.

The source asks to print 1 through 100. Returning the sequence makes that task portable and testable; use n = 100 for the reported instance. The judge checks values and order, while the editorial demonstrates the no-loop implementation.

Function

numbersWithoutLoops(n: int) → int[]

Examples

Example 1

n = 5return = [1,2,3,4,5]

The sequence contains each integer from 1 through 5 once, in increasing order.

Example 2

n = 100return = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100]

The first value is 1, the last is 100, and all 100 consecutive integers are present.

Constraints

  • 0 <= n <= 200.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public int[] numbersWithoutLoops(int n) {
    // Write your code here.
}
Checking account…