Doordash Interview Question
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-09-16Added By Anonymous
Source: Link
Company: DoorDash
Role: unknown
Interview Stage: unknown
I wanted to ask an idea to solve the question. But couldn't find the right place so posting it here, In a hope to get an answer from someone.
Find longest valid subarray in the orders array.
Each order can be delivered or picked once.
Delivery can only happen after pick up.
Ex 1: orders = ['P1', 'P1', 'D1'], return ['P1', 'D1']
Ex 2: orders = ['P1', 'P1', 'D1', 'D1'], return ['P1', 'D1']
Ex 3: orders = ['P1', 'P2' , 'P3', 'D2', 'D3'] return ['P2', 'P3', 'D2', 'D3']
Ex 4: orders = ['P13, 'D13', 'D14', 'P12', 'D12', 'P11', 'D11'] return ['P12', 'D12', 'P11', 'D11']
How can we solve this? I could not think of a better solution than brute force which is O(n^3).