{"id":"a81119db-bdd7-4b32-bf68-c6c919530ac0","name":"Climb Stairs With Minimum Moves","description":"1. You are given a number n, representing the number of stairs in a staircase.\r\n2. You are on the 0th step and are required to climb to the top.\r\n3. You are given n numbers, where ith element's value represents - till how far from the step you \r\n could jump to in a single move. You can of-course fewer number of steps in the move.\r\n4. You are required to print the number of minimum moves in which you can reach the top of \r\n staircase.\r\nNote -> If there is no path through the staircase print null.","inputFormat":"A number n\r\n.. n more elements","outputFormat":"A number representing the number of ways to climb the stairs from 0 to top.","constraints":"0 &lt;= n &lt;= 20\r\n0 &lt;= n1, n2, .. &lt;= 20","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\nusing namespace std;\n\nint cs(int arr[], int n, vector<int>& dp) {\n // write your code here\n\n}\n\nint main() {\n int n;\n cin >> n;\n int arr[n];\n for (int i = 0 ; i < n ; i++) {\n cin >> arr[i];\n }\n\n vector<int> dp(n + 1, 0);\n\n cout << cs(arr, n, dp) << endl;\n}"},"java":{"code":"//write your code here"},"python":{"code":"def fun(n, arr, dp):\n \n # write code here\n \n \n return 0\n\n\n# driver code\ndef main():\n n = int(input())\n arr = []\n \n for i in range(0,n):\n arr.append(int(input()))\n \n dp = [0]*(n+1)\n \n print(fun(n, arr, dp))\n \nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"10\r\n3\r\n3\r\n0\r\n2\r\n1\r\n2\r\n4\r\n2\r\n0\r\n0","sampleOutput":"4","questionVideo":"https://www.youtube.com/embed/d42uDPBOXSw","hints":[],"associated":[{"id":"241ebb9d-5421-473e-b328-856225abdcb7","name":"climb stairs","slug":"climb-stairs","type":4},{"id":"79f25fd1-2a3b-420d-a05b-9fab8397566e","name":"Another name for Merkel-Hellman cryptosystem is","slug":"another-name-for-merkel-hellman-cryptosystem-is","type":4},{"id":"a2aee55a-94b0-4b20-9697-3e12e35ae249","name":"climb stairs in minimum move","slug":"climb-stairs-in-minimum-move","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"b9efd9b5-0c4b-4a0f-a3cb-68def0244e4c","name":"Climb Stairs With Minimum Moves","slug":"climb-stairs-with-minimum-moves","type":1}],"next":{"id":"e317eafe-fefd-4c0c-a04e-9a0f90975ec3","name":"Climb Stairs With Minimum Moves","type":3,"slug":"climb-stairs-with-minimum-moves"},"prev":{"id":"a79ad228-c16c-4148-bc5b-9a7cbea93b3b","name":"Climb Stairs with Variable Jumps","type":3,"slug":"climb-stairs-with-variable-jumps"}}}

Climb Stairs With Minimum Moves

1. You are given a number n, representing the number of stairs in a staircase. 2. You are on the 0th step and are required to climb to the top. 3. You are given n numbers, where ith element's value represents - till how far from the step you could jump to in a single move. You can of-course fewer number of steps in the move. 4. You are required to print the number of minimum moves in which you can reach the top of staircase. Note -> If there is no path through the staircase print null.

{"id":"a81119db-bdd7-4b32-bf68-c6c919530ac0","name":"Climb Stairs With Minimum Moves","description":"1. You are given a number n, representing the number of stairs in a staircase.\r\n2. You are on the 0th step and are required to climb to the top.\r\n3. You are given n numbers, where ith element's value represents - till how far from the step you \r\n could jump to in a single move. You can of-course fewer number of steps in the move.\r\n4. You are required to print the number of minimum moves in which you can reach the top of \r\n staircase.\r\nNote -> If there is no path through the staircase print null.","inputFormat":"A number n\r\n.. n more elements","outputFormat":"A number representing the number of ways to climb the stairs from 0 to top.","constraints":"0 &lt;= n &lt;= 20\r\n0 &lt;= n1, n2, .. &lt;= 20","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\nusing namespace std;\n\nint cs(int arr[], int n, vector<int>& dp) {\n // write your code here\n\n}\n\nint main() {\n int n;\n cin >> n;\n int arr[n];\n for (int i = 0 ; i < n ; i++) {\n cin >> arr[i];\n }\n\n vector<int> dp(n + 1, 0);\n\n cout << cs(arr, n, dp) << endl;\n}"},"java":{"code":"//write your code here"},"python":{"code":"def fun(n, arr, dp):\n \n # write code here\n \n \n return 0\n\n\n# driver code\ndef main():\n n = int(input())\n arr = []\n \n for i in range(0,n):\n arr.append(int(input()))\n \n dp = [0]*(n+1)\n \n print(fun(n, arr, dp))\n \nif __name__ == \"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"10\r\n3\r\n3\r\n0\r\n2\r\n1\r\n2\r\n4\r\n2\r\n0\r\n0","sampleOutput":"4","questionVideo":"https://www.youtube.com/embed/d42uDPBOXSw","hints":[],"associated":[{"id":"241ebb9d-5421-473e-b328-856225abdcb7","name":"climb stairs","slug":"climb-stairs","type":4},{"id":"79f25fd1-2a3b-420d-a05b-9fab8397566e","name":"Another name for Merkel-Hellman cryptosystem is","slug":"another-name-for-merkel-hellman-cryptosystem-is","type":4},{"id":"a2aee55a-94b0-4b20-9697-3e12e35ae249","name":"climb stairs in minimum move","slug":"climb-stairs-in-minimum-move","type":4},{"id":"bb5bb0c6-7cba-4186-809c-4564a3a2569d","name":"DP optimizes the solution by taking advantage of which of the following:","slug":"dp-optimizes-the-solution-by-taking-advantage-of-which-of-the-following","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"52d62581-1313-45fb-aaf0-1d72a45f6a50","name":"Dynamic Programming And Greedy For Beginners","slug":"dynamic-programming-and-greedy-for-beginners","type":0},{"id":"b9efd9b5-0c4b-4a0f-a3cb-68def0244e4c","name":"Climb Stairs With Minimum Moves","slug":"climb-stairs-with-minimum-moves","type":1}],"next":{"id":"e317eafe-fefd-4c0c-a04e-9a0f90975ec3","name":"Climb Stairs With Minimum Moves","type":3,"slug":"climb-stairs-with-minimum-moves"},"prev":{"id":"a79ad228-c16c-4148-bc5b-9a7cbea93b3b","name":"Climb Stairs with Variable Jumps","type":3,"slug":"climb-stairs-with-variable-jumps"}}}
plane

Editor


Loading...

Climb Stairs With Minimum Moves

easy

1. You are given a number n, representing the number of stairs in a staircase. 2. You are on the 0th step and are required to climb to the top. 3. You are given n numbers, where ith element's value represents - till how far from the step you could jump to in a single move. You can of-course fewer number of steps in the move. 4. You are required to print the number of minimum moves in which you can reach the top of staircase. Note -> If there is no path through the staircase print null.

Constraints

0 <= n <= 20 0 <= n1, n2, .. <= 20

Format

Input

A number n .. n more elements

Output

A number representing the number of ways to climb the stairs from 0 to top.

Example

Sample Input

10 3 3 0 2 1 2 4 2 0 0

Sample Output

4

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode