help me to find the farthest left and right element for each index of arr.

Правка en2, от Erik_Demaine, 2022-04-05 08:35:43

I was trying to solve this problem Container With Most Water

Steps of my algorithm:

  1. I will calculate(for each index i of array) the left farthest element of which is greater than or equal to arr[i]
  2. I will calculate(for each index i of array) the right farthest element of which is greater than or equal to arr[i]
  3. max_ar = max (mx_ar, min({left_far[i], right_far[i], arr[i]})*((r-i)+(i-l))); where l,r can be equal to i;

help me to find the left farthest element and right farthest element for each index.

O(n)

Теги help me, greedy

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Erik_Demaine 2022-04-05 08:35:43 27
en1 Английский Erik_Demaine 2022-04-05 08:34:23 679 Initial revision (published)