The first solution will give a wrong result for: [1, 7, 5, 3, 6, 6, 7, 2, 4, 5, 8], the result should be 10, whereas it is giving 1, because it is returning at 7 > 5 ? true and the result returned is 1. I do not know what's the logic behind the first approach. Why can't the peak be in the end, or the graphs have multiple valleys?
Posts made by SanD
RE: Find Peak Element