Question: write code in java Mario and the princess Mario is a very determined warrior, and once again he is on a mission to save the

write code in java Mario and the princess Mario is a very determined warrior, and once again he is on a mission to save the princess of his kingdom. But this time, he has a very different path to follow. There are set of blocks with varying heights(possibly zero) upon which he has to jump to reach the princess. Mario somehow crossed the blocks, but now there is one more hurdle he has to pass. The enemy is very cunning, and he asked Mario a question and if he answers it correctly, Mario will get the princess with no harm. He asked, out of all the non-increasing and non-decreasing paths possible from the side he came from(left to right) which would be maximum in length? For e.g. [0,1,2,1,3] Here, there are exactly ten paths that are either non increasing or non decreasing. 0 (length=1) 1 (length=1) 2 (length=1) 1 (length=1) 3 (length=1) 0->1 (length=2) 0->1->2 (length=3) 1->2 (length=2) 2->1 (length=2) 1->3 (length=2) Note: A path can be started from any block. Here the answer would be 3, which is 7th path since it is maximum length i.e. 3, out of all possible non-decreasing and non-increasing paths. Since Mario is only a warrior, he is asking you to solve this problem for him. Explanation: Given in the problem statement. In the second test case, the maximum non-decreasing length is 2, which is 1->2. Environment Read from STDIN and write to STDOUT. For Java remove package declarations and keep the class name as solution (small case)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!