After succesfully completing the French Conundrum, you have decided to take a vacation.
Your trip is amongst the mighty mountains of Canada and whilst planning your trip, you come across a situation -
Due to the terrain of the mountains, you are confined to move forward in diagonal directions (North-East and South-East). And to avoid the risk of falling off (below x-axis is the death valley) or an accident, you have to take one step at a time.
The geographics of the track are similar to the previous problem, in a form of a 2-D rectangular lattice spanning from (0,0) to (2*m,n).
In order to plan the route of your trip, it is necessary to visualize all the routes. To fulfill the necessary requirement of visualizing the routes, you, now, have to count the paths with exactly n number of peaks (local maxima); from your initial position (although relative, consider it to be 0,0) to the end point (2*m,0).
You being an avid mathematics aficionado, are compelled to solve the problem.
Given two natural numbers, m and n (<=m), find the number of routes with the mentioned restriction, to prepare a strategy.
Example: All possible pathways for m=3
For n=2, output should be 3 > as there are 3 possible routes with exactly 2 peaks.

Solution Stats

100.0% Correct | 0.0% Incorrect
Last Solution submitted on Nov 27, 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!