Find the Cheapest Valid Round Trip

Last updated: August 16, 2026

Quick Overview

The candidate is asked to find the cheapest valid round trip given a set of travel options, focusing on efficient algorithm design and implementation.

Uber
Coding & Algorithms
Software Engineer
Uber
August 16, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

7

0

65 solved


The candidate is asked to find the cheapest valid round trip given a set of travel options, focusing on efficient algorithm design and implementation.

This question is typically asked during the onsite interview round at Uber for the Software Engineer role. The interviewer evaluates the candidate's problem-solving skills, ability to write efficient code, and how well they can handle additional requirements or constraints that may arise during the discussion. The fast-paced nature of the interview emphasizes the importance of clarity and efficiency in both thought and execution.

What the Interviewer Expects
  • Clearly outline the approach to solving the problem.
  • Implement a working algorithm with correct logic.
  • Discuss time and space complexity of the solution.
  • Be prepared to adapt the solution based on follow-up requirements.
  • Demonstrate good coding practices and clear communication.
Key Topics to Cover
Graph Algorithms
Dynamic Programming
Greedy Algorithms
Complexity Analysis
Edge Cases
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you optimize your solution for larger datasets?
  • Can you explain how your solution handles edge cases?
  • What would you change if the travel options included additional constraints?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Approach

To find the cheapest valid round trip, we can model the problem as a graph where each destination is a node and each travel option is an edge with a weight representing the cost. We will use a modifie...

Algorithm
  1. Create a graph representation of the travel options.
  2. Initialize a priority queue to explore the cheapest paths first.
  3. Use a dictionary to track the minimum cost to reach each node.
  4. Iterate...

Submit Your Answer
Markdown supported

Related Questions