Find the Minimum Cost to Reach Destination via Train
Given 'N' stations on a train route, where the train travels from station 0 to 'N'-1, determine the minimum cost to reach the final station using given ticket costs for each pair of stations (i, j) where j > i.
Input:
The first line contains an integer 'T', the number of test cases.
The first line of each test case contains a single integer 'N', indicating the size of the 'PRICE' matrix, which is N x N.
The following N lines each contain 'N' space-separated integers, representing the costs from station i to station j in the 'PRICE' matrix.
Output:
For each test case, output the minimum cost to travel from station 1 to station 'N'. Output each result on a new line.
Example:
If N = 3
PRICE[3][3] = [[0, 15, 80],
[INF, 0, 40],
[INF, INF, 0]];
The minimum cost is 55, achieved by traveling from station 1 to 2 with cost 15, then from station 2 to 3 with cost 40.
Constraints:
- 1 <= T <= 100
- 1 <= N <= 1000
Note:
Cost entries for j < i are represented by INT_MAX, which is 10000 in the matrix. You don't need to print anything - just implement and return the result.

AnswerBot
4mo
Find the minimum cost to reach the destination via train using given ticket costs for each pair of stations.
Create a 2D array to store the costs from each station to the final destination.
Use dynamic ...read more
Help your peers!
Add answer anonymously...
Deutsche Bank Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Query and Matrix Problem Statement You are given a binary matrix with 'M' rows a...read more
A Software Developer Intern was asked Q. Jump Game Problem Statement In this problem, you are given an array ARR consisti...read more
A Software Developer Intern was asked Q. Dijkstra's Shortest Path Problem Given an undirected graph with ‘V’ vertices (la...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Query and Matrix Problem Statement You are given a binary matrix with 'M' rows a...read more
A Software Developer Intern was asked Q2. Jump Game Problem Statement In this problem, you are given an array ARR consisti...read more
A Software Developer Intern was asked Q3. Dijkstra's Shortest Path Problem Given an undirected graph with ‘V’ vertices (la...read more
>
Deutsche Bank Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

