ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Software Design  >>  Software Design AllOther
 
 


 

 
 Design Patterns interview questions  Design Patterns Interview Questions
 UML interview questions  UML Interview Questions
 OOAD interview questions  OOAD Interview Questions
 Software Design Tools interview questions  Software Design Tools Interview Questions
 Requirements Management interview questions  Requirements Management Interview Questions
 Project Planning interview questions  Project Planning Interview Questions
 Project Management interview questions  Project Management Interview Questions
 Technical Writer interview questions  Technical Writer Interview Questions
 Software Design AllOther interview questions  Software Design AllOther Interview Questions
Question
I would like to submit the following question I was asked 
recently during my technical interview at Google.
I'm rephrasing the question to make it clear for everyone 
to understand:

- You are going on a one-way flight trip that includes 
billions of layovers.
- You have 1 ticket for each part of your trip (i.e: if 
your trip is from city A to city C with a layover in city 
B, then you will have 1 flight ticket from city A to city 
B, and 1 flight ticket from city B to city C.
- Each layover is unique. You are not stopping twice in the 
same city.
- You forgot the original departure city.
- You forgot the final destination city.
- All the tickets you have are randomly sorted.

Question are:
- Design an algorithm to reconstruct your trip with minimum 
complexity.
- How would you improve your algorithm.

Example:
- randomly sorted:
New York->London
San Francisco-> Hong Kong
Paris->New York
London->San Francisco
 
- sorted:
Paris->New York
New York->London
London->San Francisco
San Francisco-> Hong Kong
 Question Submitted By :: Al
I also faced this Question!!     Rank Answer Posted By  
 
  Re: I would like to submit the following question I was asked recently during my technical interview at Google. I'm rephrasing the question to make it clear for everyone to understand: - You are going on a one-way flight trip that includes billions of layovers. - You have 1 ticket for each part of your trip (i.e: if your trip is from city A to city C with a layover in city B, then you will have 1 flight ticket from city A to city B, and 1 flight ticket from city B to city C. - Each layover is unique. You are not stopping twice in the same city. - You forgot the original departure city. - You forgot the final destination city. - All the tickets you have are randomly sorted. Question are: - Design an algorithm to reconstruct your trip with minimum complexity. - How would you improve your algorithm. Example: - randomly sorted: New York->London San Francisco-> Hong Kong Paris->New York London->San Francisco - sorted: Paris->New York New York->London London->San Francisco San Francisco-> Hong Kong
Answer
# 1
1) Assuming the data in 2 dim array. (2 Columns: FROM 
destination & TO destination)
2) Sort the array (any standard sorting logic) using column 
1 i.e. FROM destination.
3) Take "TO" destination value of row 1 and use binary 
search to search its match in "FROM" destination column 
from row 2 to n
	If match found, adjust that row as row 2. (Swap 
pointers in place of physical data)
		Take "TO" destination value of row 2 and 
use binary search to search its match in "FROM" destination 
column from row 3 to n
		continue this logic till as long as a match 
is found. 
		
		if match not found. 
		Resort the remaining unadjusted rows 
using "TO destination" column.
			Take "From" destination value of 
row 1 and use binary search to search its match in "To" 
column in all unadjusted rows. 
			Match must be found otherwise data 
incorrect. adjust that row as row -1. (Swap pointers in 
place of physical data)
			Continue this till end of the 
array. 
			
			Now you have the sorted list. 


I am sure there can better ways to achieve the same.
 
Is This Answer Correct ?    0 Yes 0 No
Raghvendra
 
  Re: I would like to submit the following question I was asked recently during my technical interview at Google. I'm rephrasing the question to make it clear for everyone to understand: - You are going on a one-way flight trip that includes billions of layovers. - You have 1 ticket for each part of your trip (i.e: if your trip is from city A to city C with a layover in city B, then you will have 1 flight ticket from city A to city B, and 1 flight ticket from city B to city C. - Each layover is unique. You are not stopping twice in the same city. - You forgot the original departure city. - You forgot the final destination city. - All the tickets you have are randomly sorted. Question are: - Design an algorithm to reconstruct your trip with minimum complexity. - How would you improve your algorithm. Example: - randomly sorted: New York->London San Francisco-> Hong Kong Paris->New York London->San Francisco - sorted: Paris->New York New York->London London->San Francisco San Francisco-> Hong Kong
Answer
# 2
actually, you have a trip going in and out of each city 
except the final to (sink) and from (source) cities. the 
source and the sink appear only once in the table, the 
source in the first column, sink in the second. this can be 
found by reading the table once. 

then each city must appear exactly once in the two columns.
so you can defenitely take no wrong trip and get stuck so 
simplest thing to do is to start looking for the only 
possible next flight in the table, starting from original 
source. this will take you to your destination in n^2 
complexity. 

so maybe we can use some clever sorting knowing the maximum 
letters in each city and sorting them alphabetically or we 
can use some hashmap. one of these might do it in nlogn 
probably but a bit dont feel like thinking too much. 

if the flights are sorted you can definitely do it in nlogn 
since you will use binary search to find the next flight in 
the sorted array.which is n times logn.

hope this helped.
 
Is This Answer Correct ?    0 Yes 0 No
Ivan Krivulev
 
 
 

 
 
 
Other Software Design AllOther Interview Questions
 
  Question Asked @ Answers
 
what is meaning for .net?ten introduction of software tools? Wipro1
vb.net with Sql sever2005  1
Please send me Sample papers National Informatics Centre (NIC) Programmer Vacency NIC135
What is platform-driven ESL design?  2
what is another name for Spiral SDLC?  2
What's the Difference Between a Dummy and a Comp?  1
In a 100 day project how much time would be spent on requirements capture.  2
1-What is Report Painter ? ALE / IDoc. ? User Exit ? Variances ? Please revert back with answer & if u have any Documents for above question, then plse. send me in my mail ID- sundarnmishra@gmail.com thanks & regards Sundar Videocon1
I would like to submit the following question I was asked recently during my technical interview at Google. I'm rephrasing the question to make it clear for everyone to understand: - You are going on a one-way flight trip that includes billions of layovers. - You have 1 ticket for each part of your trip (i.e: if your trip is from city A to city C with a layover in city B, then you will have 1 flight ticket from city A to city B, and 1 flight ticket from city B to city C. - Each layover is unique. You are not stopping twice in the same city. - You forgot the original departure city. - You forgot the final destination city. - All the tickets you have are randomly sorted. Question are: - Design an algorithm to reconstruct your trip with minimum complexity. - How would you improve your algorithm. Example: - randomly sorted: New York->London San Francisco-> Hong Kong Paris->New York London->San Francisco - sorted: Paris->New York New York->London London->San Francisco San Francisco-> Hong Kong Google2
What is the difference between a web-based and installed software?  1
 
For more Software Design AllOther Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com