Solve Four Interview Coding Problems
Company: Pinterest
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question set evaluates algorithmic problem-solving skills including graph traversal and itinerary reconstruction, time-sorted search and binary search, grid-based simulation of ray traversal, and data structure design for efficient updates and leaderboard generation.
Part 1: Reconstruct Itinerary from Airline Tickets
Constraints
- 0 <= len(tickets) <= 10^4
- Each ticket is a pair [from, to] of non-empty strings
- Duplicate tickets may exist
- Assume at least one valid itinerary exists for the given start, except the empty-ticket case
Examples
Input: ([['MUC', 'LHR'], ['JFK', 'MUC'], ['SFO', 'SJC'], ['LHR', 'SFO']], 'JFK')
Expected Output: ['JFK', 'MUC', 'LHR', 'SFO', 'SJC']
Explanation: There is only one valid way to use all tickets starting from JFK.
Input: ([['JFK', 'SFO'], ['JFK', 'ATL'], ['SFO', 'ATL'], ['ATL', 'JFK'], ['ATL', 'SFO']], 'JFK')
Expected Output: ['JFK', 'ATL', 'JFK', 'SFO', 'ATL', 'SFO']
Explanation: Multiple itineraries exist, so the lexicographically smallest valid one must be chosen.