Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA
Starting at step 0, you climb to step 6 taking steps of 1 or 2 each time. How many distinct sequences of steps are possible?
- A. 14
- B. 12
- C. 13
- D. 64
Correct answer: C. 13
This is the Fibonacci-style recurrence dp[i] = dp[i-1] + dp[i-2], giving 13 for n = 6. The total 2^6 = 64 would count sequences that overshoot step 6.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many integers from 1 to 1000 inclusive are divisible by 8 and have an even number of 1-bits in binary?
- Repeatedly merge two values into their sum at cost equal to that sum, starting from [1, 2, 3, 4]. What is the minimum total cost?
- How many integers from 1 to 100 inclusive have an odd number of positive divisors?
- What is the length of the longest common substring (contiguous) of "abcdef" and "zcdemf"?
- When converting the infix expression "(a+b)(c-d)/e" to postfix, how many operator symbols appear in the postfix output?
- What is the sum of all odd positive divisors of 180?