A Distance Maximizing Problem

Given an array A of integers, find the maximum of j-i subjected to the constraint of A[i] < A[j].

发现这三天做的题目都是一个类型的。 就是采用一个header 一个 tail 指针 同时卡 一个array的两个边界 来在O(n) 的时间内 完成 brute force 需要O(n2) 才能完成的任务。

 

这类问题的相似处都是找max, 采用的 也都是 先移动tail, 当不能移动tail时, 移动header 来动态的控制边界。

 

你可能感兴趣的:(max)