Uber L5a interview question

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-04-20Added By Anonymous
Source: Link

Company: Uber

Role: Senior Software Engineer



Original Post Content:


// As a theater booking system with N seats (1...N), You made a mistake while assigning tickets. And it ended up assigning 2 tickets to everyone instead of 1.


// M (where M < N) people who tried to book the ticket in your theater got 2 tickets instead of 1.

// so basically all the people who wants to watch the show ends up with two tickets.


// - To solve this mistake you decided to be smart and figure out if it's possible to cancel just 1 tickets instead of re assigning tickets to everyone?

// - If it's possible to just cancel one ticket which ticket you will cancel? (return list which represent cancelled ticket for ith person at ith index )


// Example:


// N: 5

// bookings : (6,2) (1,2) (1,6) (2,3) (3,4) (5,2)

// (1,2) (1,2) (2,1) (3,4) (5,7) -> no


// answer:

// Yes,

// cancel (1,2,2,3,2)

Comments