Erik_Demaine's blog

By Erik_Demaine, history, 2 years ago, In English

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)

Full text and comments »

  • Vote: I like it
  • -2
  • Vote: I do not like it