Jooney's Amusement Park
Coding Problem Keys
Jooney's Amusement Park
Problem Statement
In the amusement park at Jooney's amusement, there is a "Weighted Maze" challenge. This consist of a set of East West roads and North South roads (referred to as up down roads). There are N intersections and each intersection has a block of iron bar, the weight of which is given. You enter the maze at the top left corner. The exit from the maze is at the bottom right corner. Movement at any intersection is to the right or down provided a road exists in that direction.
At each Intersection you pass through, you must exchange the weight in your cart with the weight of the bar at the intersection if it is heavier than the weight in you have in the cart.
The objective is to determine a path through the maze along the roads so that one can exit the maze with minimum weight in the cart.
Input Format
Output Format
The first line contains the minimum weight in the cart at the exit.Constraints
2 <= N <= 100Example Input/Output 1
Input
4Output
Example Input/Output 2
Input
5Output
Max Execution Time Limit: 5000 millisecs
Solution
Programming Language: Python 3 Language
n=int(input())
l=[list(map(int, input().split(','))) for i in range(n)]
s=[[0]*n for i in range(n)]
s[0][0]=l[0][0]
for i in range(1,n):
s[0][i]=max(s[0][i-1], l[0][i])
s[i][0]=max(s[i-1][0], l[i][0])
for r in range(1,n):
for c in range(1,n):
mi=min(s[r-1][c],s[r][c-1])
s[r][c]=max(mi, l[r][c])
print(s[-1][-1])
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments