Day-1 — Find the peak element

Abhishek Raj
1 min readJul 1, 2020

Hello everyone, how are you, let’s start again “the competitive Coding”

Divide and Conquer Algorithm

Find the peak element.

Given an array of integers. Find a peak element in it. An array element is a peak if it is NOT smaller than its neighbors. For corner elements, we need to consider only one neighbor.
Very interesting problem, you need to give a little attention on the problem itself.

The most elegant way of writing the mid is peak
if ((mid == 0 || arr[mid - 1] <= arr[mid]) &&

(mid == n - 1 || arr[mid + 1] <= arr[mid]))

Before looking into the solution or code, think for a while and spoiler alert it is based on divide and conquer method (binary search).

You can submit the code here,
https://leetcode.com/problems/find-peak-element/

--

--

Abhishek Raj

Love to code, explore life, started journey within myself, Yoga Practitioner