{"id":"5266c23f-f658-4437-9fef-780dac8350a2","name":"Climb Stairs With Variable Jumps","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. \r\n You can of course jump fewer number of steps in the move.\r\n4. You are required to print the number of different paths via which you can climb to the top.","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>\r\nusing namespace std;\r\n\r\nint cs(int arr[], int n){\r\n // write your code here\r\n\r\n return 0;\r\n}\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\n int arr[n];\r\n for(int i = 0 ; i < n ;i++){\r\n cin>>arr[i];\r\n }\r\n cout<<cs(arr,n)<<endl;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"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":"5","questionVideo":"https://www.youtube.com/embed/uNqoQ0sNZCM","hints":[],"associated":[{"id":"4bd44614-4f20-4b10-b2ac-de323c86dc5a","name":"Dynamic Programming optimise","slug":"dynamic-programming-optimise","type":4},{"id":"64cd1120-2f7c-43bc-8000-b7f83e4ff400","name":"concept of Dynamic Programmng","slug":"concept-of-dynamic-programmng","type":4},{"id":"b02d3b95-14db-4ded-ab95-e7699a7ecdb6","name":"Climb Stair problem","slug":"climb-stair-problem","type":4},{"id":"ff68602a-3f10-4292-819f-45c4574d1f72","name":"five spots","slug":"five-spots","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":"18793f55-3ca7-45c8-881c-3fa279236331","name":"Climb Stairs With Variable Jumps","slug":"climb-stairs-with-variable-jumps","type":1}],"next":{"id":"a79ad228-c16c-4148-bc5b-9a7cbea93b3b","name":"Climb Stairs with Variable Jumps","type":3,"slug":"climb-stairs-with-variable-jumps"},"prev":{"id":"f3de766e-1e67-4dce-8cdb-b5b588f1f159","name":"Climb Stairs","type":3,"slug":"climb-stairs"}}}

# Climb Stairs With Variable Jumps

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 jump fewer number of steps in the move. 4. You are required to print the number of different paths via which you can climb to the top.

{"id":"5266c23f-f658-4437-9fef-780dac8350a2","name":"Climb Stairs With Variable Jumps","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. \r\n You can of course jump fewer number of steps in the move.\r\n4. You are required to print the number of different paths via which you can climb to the top.","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>\r\nusing namespace std;\r\n\r\nint cs(int arr[], int n){\r\n // write your code here\r\n\r\n return 0;\r\n}\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\n int arr[n];\r\n for(int i = 0 ; i < n ;i++){\r\n cin>>arr[i];\r\n }\r\n cout<<cs(arr,n)<<endl;\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"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":"5","questionVideo":"https://www.youtube.com/embed/uNqoQ0sNZCM","hints":[],"associated":[{"id":"4bd44614-4f20-4b10-b2ac-de323c86dc5a","name":"Dynamic Programming optimise","slug":"dynamic-programming-optimise","type":4},{"id":"64cd1120-2f7c-43bc-8000-b7f83e4ff400","name":"concept of Dynamic Programmng","slug":"concept-of-dynamic-programmng","type":4},{"id":"b02d3b95-14db-4ded-ab95-e7699a7ecdb6","name":"Climb Stair problem","slug":"climb-stair-problem","type":4},{"id":"ff68602a-3f10-4292-819f-45c4574d1f72","name":"five spots","slug":"five-spots","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":"18793f55-3ca7-45c8-881c-3fa279236331","name":"Climb Stairs With Variable Jumps","slug":"climb-stairs-with-variable-jumps","type":1}],"next":{"id":"a79ad228-c16c-4148-bc5b-9a7cbea93b3b","name":"Climb Stairs with Variable Jumps","type":3,"slug":"climb-stairs-with-variable-jumps"},"prev":{"id":"f3de766e-1e67-4dce-8cdb-b5b588f1f159","name":"Climb Stairs","type":3,"slug":"climb-stairs"}}}

Editor

# Climb Stairs With Variable Jumps

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 jump fewer number of steps in the move. 4. You are required to print the number of different paths via which you can climb to the top.

## 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

5

Question Video

Discussions

Show Discussion

Related Resources