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 

The first line contains the number of intersections N.

 Output Format 

The first line contains the minimum weight in the cart at the exit.

 Constraints 

2 <= N <= 100

 Example Input/Output 1 

 Input 

4
1,8,21,7
19,17,10,20
2,18,23,22
14,25,4,13

 Output 

22

 Example Input/Output 2 

 Input 

5
1,69,51,68,19
98,92,100,77,54
8,32,73,31,71
55,68,98,41,42
32,70,16,57,60

 Output 

71

 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

Popular Posts

Turning Book Pages

Maximum Sub Square Sum

Shift Largest Digit - Sum

Reverse Column - First and Last

String With Most Vowels

Multiply Three Numbers