id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

UIL2015_INVA_07_MOUNTAIN


You love climbing mountains, and in fact, you think of yourself to be quite exceptional at the sport. Your friend decides to test that theory and presents you with a series of challenges. For each challenge, she gives you the layout of a “mountain” of blocks as an n x n grid of positive integers, where each integer in the grid represents the height of that location in blocks. She tells you your starting position will always be in the top left corner. Given this information, she asks if you think you can reach the top.

Rather than rush off to try and prove you really are the greatest mountain climber in town, you decide to approach things logically. In the grid layout, each block unit is the equivalent of 5 meters. You figure that you can only climb up one single block at a time, but you can jump down up to 2 blocks at a time. Additionally, you can only go up or down adjacent blocks (left, right, up, down). Armed with this knowledge, you write a program to determine if it is possible for you to reach the highest block.

The input for this problem will be five one-dimensional integer arrays, indicating the rows of a 2D array of the height values of the mountain. You can use the following code to create the 2D array:

int[][] mountain = {r1,r2,r3,r4,r5};

Return true if it is possible to reach the highest point of the mountain. There will always be a single highest point. Remember, you start at the top left corner.


UIL2015_INVA_07_MOUNTAIN([3, 1, 3, 1, 1], [1, 1, 3, 7, 2], [2, 3, 3, 7, 3], [4, 4, 7, 7, 4], [9, 8, 7, 6, 5]) → true
UIL2015_INVA_07_MOUNTAIN([3, 1, 3, 1, 1], [1, 1, 3, 7, 2], [2, 3, 3, 7, 3], [4, 4, 7, 7, 4], [9, 7, 7, 6, 5]) → false
UIL2015_INVA_07_MOUNTAIN([3, 1, 2, 1, 1], [6, 5, 4, 7, 2], [7, 3, 3, 7, 3], [8, 4, 3, 2, 4], [9, 7, 7, 6, 5]) → true

...Save, Compile, Run (ctrl-enter)

public boolean UIL2015_INVA_07_MOUNTAIN(int[] r1, int[] r2, int[] r3, int[] r4, int[] r5) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy