Fishmonger Toll Optimization Problem

A fishmonger needs to transport goods from a port to a market, crossing multiple states each requiring a toll. The goal is to minimize the toll costs while ensuring the journey is completed within a specified time limit to prevent spoilage of the goods.

Explanation:

You are provided with ‘N’ states and a time limit ‘M’. Your task is to determine the smallest toll amount the fishmonger needs to pay to reach the market from the port within the given time. The journey starts at the 0th state (port) and ends at the 'N'-1 state (market).

Input:

First line: Integer ‘T’ for the number of test cases.
For each test case:
- Two integers ‘N’ and ‘M’ indicating the number of states and the maximum allowable time.
- Next ‘N’ lines: ‘N’ integers representing the ‘Time’ matrix indicating time from state ‘i’ to state ‘j’.
- Next ‘N’ lines: ‘N’ integers representing the ‘Toll’ matrix indicating toll cost from state ‘i’ to state ‘j’.

Output:

For each test case, output the minimum toll cost required to reach the market from the port within the given time, or -1 if it is not possible.

Example:

Input:
N = 2, M = 4,
Time = [[0, 2], [3, 0]],
Toll = [[0, 10], [5, 0]]
Output:
10

Constraints:

  • 1 <= T <= 10
  • 2 <= N <= 50
  • 1 <= M <= 1000
  • 0 <= Toll[i][j] <= 108
  • 0 <= Time[i][j] <= 1000

Note:

You do not need to print anything; your implementation should return the result for each test case.

AnswerBot
4mo

The Fishmonger Toll Optimization Problem involves minimizing toll costs while ensuring timely delivery of goods from a port to a market.

  • Given 'N' states and a time limit 'M', find the smallest toll am...read more

Help your peers!
Select
Add answer anonymously...

Amazon Software Developer Intern interview questions & answers

A Software Developer Intern was asked 4mo agoQ. Given a linked list, find the n'th node from the end of the list.
A Software Developer Intern was asked 4mo agoQ. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ. Given a matrix, find the shortest distance between two given points located anyw...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked 4mo agoQ1. Given a linked list, find the n'th node from the end of the list.
A Software Developer Intern was asked 4mo agoQ2. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ3. Given a matrix, find the shortest distance between two given points located anyw...read more
Amazon Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits