BackmediumBacktracking Cred

Travel Itinerary Combinations Solution

Problem Statement

Given a list of cities and their corresponding airports, find all possible travel itineraries such that each traveler visits exactly two cities.

Example 1
Input
{"cities":["City A","City B","City C"],"airports":["Airport A","Airport B","Airport C"]}
Output
[["City A","City B"],["City A","City C"],["City B","City A"],["City B","City C"],["City C","City A"],["City C","City B"]]

Explanation: Each traveler visits exactly two cities

Constraints

  • Each city and airport code is a string in the format 'city-code' with no duplicates.
  • All travel itineraries consist of exactly two connected cities.
  • Cities that have been visited are not re-visited.
  • The number of travelers is fixed at 3 or N.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free