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

Answers were Sorted based on User's Feedback



I would like to submit the following question I was asked recently during my technical interview a..

Answer / raghvendra

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 ?    3 Yes 0 No

I would like to submit the following question I was asked recently during my technical interview a..

Answer / ivan krivulev

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 ?    2 Yes 0 No

I would like to submit the following question I was asked recently during my technical interview a..

Answer / samir

Find the ticket which has a unique TO destination. That
destination should not occur in FROM field in any ticket

:)

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Software Design AllOther Interview Questions

How can authoring tools support the production of accessible Web content?

0 Answers  


What are virtual platforms for software development?

0 Answers  


What are the advantages Information System Architecture Framework in term of analysis and system design

0 Answers  


how to downlaod image to target system? what is the vi editor?

0 Answers  


The procedure of hiring fresher’s in CEI is as follows. Only graduates from an engineering background with specialization in ECE (Electronics and Communications), Computer science and IT streams are accepted. We also accept students who have completed their Masters in Computer Applications. Only those candidates who have a score of 70% and above throughout their academics are considered. We follow a four level procedure for selecting any fresher to be part of our highly skilled technical team. These include: 1. Written Test 2. Technical Interview 1 – Conducted by CEI Developers 3. Technical Interview 2 – Conducted by CEI Project Managers 4. HR Discussion The written test is divided into 3 sections as mentioned below: 1. Logical: Critical Reasoning and Analytical Reasoning – 30 Questions 2. Quantitative Aptitude – 25 Questions 3. Technical Questions – 25 Questions Logical: These questions primarily test the analytical and critical thinking skills of the applicants. It tests the most integral skills of the applicant, the logical consistency in thought, understanding and processing data and making valid conclusions from them, and out of the box thinking. The best part about logical reasoning is that it does not require any learning or prior knowledge. Example: • If the positions of the first ten letters and the last ten letters in the English alphabet are interchanged such as that the first and the seventeenth the second and the eighteenth letters are interchanged and this continues till the tenth letter is interchanged with the twenty-sixth letter, which letter will be the fifth to the right of the twelfth letter from the right after this rearrangement? • There is a 3 digit number. The sum of the digits is 17, and two of the digits are the same. The unique digit subtracted from one of the other digits equals a positive even number. What is the digit that is different from the other two digits? Quantitative aptitude Section consists of questions related to Simplifications, Data Sufficiency, and from the topics of Arithmetic. For e.g.; Fraction, Profit and Loss, Combinations and Permutations, Percentage problems, Ratio, Probability, Allegations and Mixtures, Time and distance, Time and work, Measurements, etc. Example: • A sales person by mistake multiplied a number and got the answer as 3, instead of dividing the number by 3. What is the answer he should have actually got? • A traveler walks a certain distance. Had he gone half a kilometer an hour faster, he would have walked in 4/5 of the time, and had he gone half a kilometer an hour slower, he would have walked 2 ½ hours longer. What is the distance? • Two taps A and B fill a tank in 12 and 20 hours respectively and a third tap C empties it in 15 hrs. In how many hours will the tank be filled if the taps A and B are opened simultaneously and C is opened after two hours.? Technical Section consists of sections related to basics concepts of programming languages, and some basic entry level programming are given to assess the applicant’s ability to solve the program. Example: • An alternate to using interrupts for I/O devices is • The main advantage of using indexes is • PRODUCT Product ID Product Description Manufacturer ID MANUFACTURER Manufacturer ID Manufacturer Name Referring to the above table, what type of relationship exists between the Product table and the Manufacturer table?  Once a candidate clears the written test they will be considered for the second round.

0 Answers  






What is the difference between a web-based and installed software?

1 Answers  


waht do you mean by capital market

2 Answers   TATA,


In a theatre having capacity of 800 divided into three. capacity of first is 270, capacity of second is 190 more than third. find capacity of second.

14 Answers   Infosys,


what is another name for Spiral SDLC?

3 Answers  


what is meaning for .net?ten introduction of software tools?

2 Answers   Wipro,


what stage/s of the development lifecycle should end users be involved?

0 Answers   Microsoft,


Where we have to use RCVF and where we have to use SNDRCVF. Basically what is difference between RCVF and SNDRCVF?

0 Answers   IBM,


Categories