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? Algorithms algorithms time-complexity + – Anirban Biswas asked Dec 12, 2016 • edited Jun 29, 2022 by makhdoom ghaya Anirban Biswas 496 views answer comment Share Follow See 1 comment See all 1 1 comment reply Prashant. commented Dec 12, 2016 reply Follow Share Not sure O(n5) 0 votes 0 votes Please log in or register to add a comment.
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) shayal chhabra answered Dec 12, 2016 shayal chhabra comment Share Follow See all 0 reply Please log in or register to add a comment.