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

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

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)

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

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