This is an Amazon interview Question.I have solved this problem in O(n) using dynamic
programming.But I want to know can there be more optimization than O(n)
for e.g. suppose below is the array
3 7 1 4 2 4 returns 4
5 4 3 2 1 returns Nothing
4 3 2 2 3 returns 1
This is the code i have written Code
Lets say you’ve got
int A[N].Complexity O(N).
You need to examine N elements so O(N) is best what you can get.