`{"id":"3e6dbb45-471e-440b-9372-1617bf81bbb2","name":"Count Of Valleys And Mountains","description":"1. You are given a number n, representing the number of upstrokes / and number of downstrokes .\r\n2. You are required to find the number of valleys and mountains you can create using strokes.\r\nE.g.\r\n\r\n<img src=\"http://pepcoding.com/resources/ojquestionresource/images/countvalleys2.JPG\" alt=\"countvalleys\">\r\n\r\nNote -> At no point should we go below the sea-level. (number of downstrokes should never be more than number of upstrokes).","inputFormat":"A number n","outputFormat":"A number representing the number of valleys and mountains you can create using strokes.","constraints":"0 &lt;= n &lt;= 15","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4","sampleOutput":"14","questionVideo":"https://www.youtube.com/embed/hM_FJnrP1kk?end=139","hints":[],"associated":[],"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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"a7c4671c-eeb5-4df7-8e71-12d73cfbbf83","name":"Count Of Valleys And Mountains","slug":"count-of-valleys-and-mountains","type":1}],"next":{"id":"dccad2d6-0b63-4737-acd1-4cc9160a6cef","name":"Count Brackets","type":1,"slug":"count-brackets"},"prev":{"id":"0f01c6f8-a022-4626-952d-c66ac99393f0","name":"Count Palindromic Substrings","type":1,"slug":"count-palindromic-substrings"}}}`

# Count Of Valleys And Mountains

1. You are given a number n, representing the number of upstrokes / and number of downstrokes . 2. You are required to find the number of valleys and mountains you can create using strokes. E.g. <img src="http://pepcoding.com/resources/ojquestionresource/images/countvalleys2.JPG" alt="countvalleys"> Note -> At no point should we go below the sea-level. (number of downstrokes should never be more than number of upstrokes).

`{"id":"3e6dbb45-471e-440b-9372-1617bf81bbb2","name":"Count Of Valleys And Mountains","description":"1. You are given a number n, representing the number of upstrokes / and number of downstrokes .\r\n2. You are required to find the number of valleys and mountains you can create using strokes.\r\nE.g.\r\n\r\n<img src=\"http://pepcoding.com/resources/ojquestionresource/images/countvalleys2.JPG\" alt=\"countvalleys\">\r\n\r\nNote -> At no point should we go below the sea-level. (number of downstrokes should never be more than number of upstrokes).","inputFormat":"A number n","outputFormat":"A number representing the number of valleys and mountains you can create using strokes.","constraints":"0 &lt;= n &lt;= 15","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4","sampleOutput":"14","questionVideo":"https://www.youtube.com/embed/hM_FJnrP1kk?end=139","hints":[],"associated":[],"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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"a7c4671c-eeb5-4df7-8e71-12d73cfbbf83","name":"Count Of Valleys And Mountains","slug":"count-of-valleys-and-mountains","type":1}],"next":{"id":"dccad2d6-0b63-4737-acd1-4cc9160a6cef","name":"Count Brackets","type":1,"slug":"count-brackets"},"prev":{"id":"0f01c6f8-a022-4626-952d-c66ac99393f0","name":"Count Palindromic Substrings","type":1,"slug":"count-palindromic-substrings"}}}`

Editor

# Count Of Valleys And Mountains

easy

1. You are given a number n, representing the number of upstrokes / and number of downstrokes . 2. You are required to find the number of valleys and mountains you can create using strokes. E.g. Note -> At no point should we go below the sea-level. (number of downstrokes should never be more than number of upstrokes).

0 <= n <= 15

## Format

A number n

### Output

A number representing the number of valleys and mountains you can create using strokes.

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}14`

Question Video

Discussions

Show Discussion

Related Resources