Блог пользователя jaswin6860

Автор jaswin6860, история, 4 дня назад, По-английски

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).

Полный текст и комментарии »

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится