edited by
496 views
0 votes
0 votes
Let A =[a1, a2, …, an] be a one-dimensional array of integers define a MEGA-PEAK in A to be an element ai belongs A such that ai >= aj for all aj with | j – i | <= 2. What is the time complexity to find MEGA-PEAK?
edited by

1 Answer

0 votes
0 votes
Ans is O(n)

It will traverse for all the elements from 1 to n and for any i only 4 value of j are possible i-1,i-2,i+1,i+2 so its comparison will take constant time, its time complexity is O(n)

Related questions

0 votes
0 votes
0 answers
2
0 votes
0 votes
1 answer
3
NeelParekh asked Jul 27, 2023
279 views
If an array is split in the form of increasing and decreasing order then what is TC to find minimum element in the array?
2 votes
2 votes
1 answer
4
h4kr asked Dec 30, 2022
473 views
What is the correct time complexity in $\theta()$ ?