Looking for an alternative solution apart from brute force

Правка en1, от jaswin6860, 2024-09-16 05:11:38

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.

  1. Each order can be delivered or picked once.
  2. 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']

How can we solve this? I could not think of a better solution than brute force which is O(n^3).

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский jaswin6860 2024-09-16 05:11:38 646 Initial revision (published)