`{"id":"99afec4a-b4a5-4a32-983c-6eb66b0b76fe","name":"Find Itinerary From Tickets","description":"1. You are given number N and 2*N number of strings that represent a list of N tickets(source and destination).\r\n2. You have to find the itinerary in order using the given list of tickets.\r\n\r\nAssumption -> The input list of tickets is not cyclic and there is one ticket from every city except the final destination. ","inputFormat":"A number N\r\nN number of lines, where each line contains 2 strings.","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 100","sampleCode":{"cpp":{"code":"#include \"bits/stdc++.h\"\nusing namespace std;\n\n\nint main(){\n int n;cin>> n;\n //Write your code here\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint noofpairs_src_des = scn.nextInt();\r\n\t\tHashMap<String, String> map = new HashMap<>();\r\n\t\tfor (int i = 0; i < noofpairs_src_des; i++) {\r\n\t\t\tString s1 = scn.next();\r\n\t\t\tString s2 = scn.next();\r\n\t\t\tmap.put(s1, s2);\t\r\n\t\t}\r\n\r\n\t\t//write your code here\r\n\r\n\r\n\t}\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\nChennai Banglore \r\nBombay Delhi \r\nGoa Chennai \r\nDelhi Goa ","sampleOutput":"Bombay -> Delhi -> Goa -> Chennai -> Banglore.","questionVideo":"https://www.youtube.com/embed/4mi2rO4D_Xk?end=58","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"508ed769-8428-4fd2-a24a-31e6a66636dd","name":"Find Itinerary From Tickets","slug":"find-itinerary-from-tickets","type":1}],"next":{"id":"63207322-4917-4689-ad3e-3d5ea78e140f","name":"Find Itinerary From Tickets MCQ","type":0,"slug":"find-itinerary-from-tickets-mcq"},"prev":{"id":"c515dd07-1fff-4fc4-8230-772cddd4de9e","name":"Number Of Employees Under Every Manager","type":3,"slug":"number-of-employees-under-every-manager"}}}`

# Find Itinerary From Tickets

1. You are given number N and 2*N number of strings that represent a list of N tickets(source and destination). 2. You have to find the itinerary in order using the given list of tickets. Assumption -> The input list of tickets is not cyclic and there is one ticket from every city except the final destination.

`{"id":"99afec4a-b4a5-4a32-983c-6eb66b0b76fe","name":"Find Itinerary From Tickets","description":"1. You are given number N and 2*N number of strings that represent a list of N tickets(source and destination).\r\n2. You have to find the itinerary in order using the given list of tickets.\r\n\r\nAssumption -> The input list of tickets is not cyclic and there is one ticket from every city except the final destination. ","inputFormat":"A number N\r\nN number of lines, where each line contains 2 strings.","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 100","sampleCode":{"cpp":{"code":"#include \"bits/stdc++.h\"\nusing namespace std;\n\n\nint main(){\n int n;cin>> n;\n //Write your code here\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint noofpairs_src_des = scn.nextInt();\r\n\t\tHashMap<String, String> map = new HashMap<>();\r\n\t\tfor (int i = 0; i < noofpairs_src_des; i++) {\r\n\t\t\tString s1 = scn.next();\r\n\t\t\tString s2 = scn.next();\r\n\t\t\tmap.put(s1, s2);\t\r\n\t\t}\r\n\r\n\t\t//write your code here\r\n\r\n\r\n\t}\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"4\r\nChennai Banglore \r\nBombay Delhi \r\nGoa Chennai \r\nDelhi Goa ","sampleOutput":"Bombay -> Delhi -> Goa -> Chennai -> Banglore.","questionVideo":"https://www.youtube.com/embed/4mi2rO4D_Xk?end=58","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"508ed769-8428-4fd2-a24a-31e6a66636dd","name":"Find Itinerary From Tickets","slug":"find-itinerary-from-tickets","type":1}],"next":{"id":"63207322-4917-4689-ad3e-3d5ea78e140f","name":"Find Itinerary From Tickets MCQ","type":0,"slug":"find-itinerary-from-tickets-mcq"},"prev":{"id":"c515dd07-1fff-4fc4-8230-772cddd4de9e","name":"Number Of Employees Under Every Manager","type":3,"slug":"number-of-employees-under-every-manager"}}}`

Editor

# Find Itinerary From Tickets

easy

1. You are given number N and 2*N number of strings that represent a list of N tickets(source and destination). 2. You have to find the itinerary in order using the given list of tickets. Assumption -> The input list of tickets is not cyclic and there is one ticket from every city except the final destination.

1 <= N <= 100

## Format

### Input

A number N N number of lines, where each line contains 2 strings.

### Output

Check the sample ouput and question video.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 Chennai Banglore Bombay Delhi Goa Chennai Delhi Goa ```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}Bombay -> Delhi -> Goa -> Chennai -> Banglore.`

Question Video

Discussions

Show Discussion

Related Resources