🔺 RALLY 2 Coding Challenge
Problem Name: Mountain Descent – The Fastest Trail
The students of Motihari College of Engineering, under the adventurous banner of
the ZEROONE Coding Club, have embarked on a thrilling mountain expedition as part
of the RALLY 2 challenge. The mountain, shaped like a right-angled triangle,
represents a map of difficulty levels — each number indicates how difficult it is
to cross that particular step.
Starting from the summit (the top of the triangle), they must descend to the base
in such a way that the total difficulty is minimized. At each level of the
mountain, a student can move only to one of the two adjacent steps directly below —
either straight down or diagonally down to the right
(In simple language, if you are on index j on the current row, you may move to
either index j or index j + 1 on the next row).
Your mission is to help them find the safest and most efficient path with the least
total difficulty from top to bottom of the mountain!
Input:
The first line contains an integer n — the height of the mountain (i.e., the number
of rows in the triangle).
The next n lines each contain space-separated integers representing the difficulty
levels at that level of the mountain.
The i-th line contains exactly i integers.
Constraints:
1 ≤ n ≤ 200
-10⁴ ≤ triangle[i][j] ≤ 10⁴
Output:
An integer representing the minimum total difficulty to descend from the top to the
base.
Example 1:
Input:
5
7
6 3
3 8 5
11 2 10 9
1 4 7 6 3
Output:
22
Explanation:
The best path is: 7 → 6 → 2 → 4 → 3 = 22
Example 2:
Input:
1
-7
Output:
-7
Explanation:
The best path is: -7