Codeforces and Polygon may be unavailable from May 23, 4:00 (UTC) to May 23, 7:00 (UTC) due to technical maintenance. ×

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

Revision en2, by 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)

Tags help me, greedy

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Erik_Demaine 2022-04-05 08:35:43 27
en1 English Erik_Demaine 2022-04-05 08:34:23 679 Initial revision (published)