A peak element is an element that is strictly greater than its neighbors.
Given a 0-indexed integer array nums, find a peak element, and return its index. If the array contains multiple peaks, return the index to any of the peaks.
You may imagine that nums[-1] = nums[n] = -∞. In other words, an element is always considered to be strictly greater than a neighbor that is outside the array.
You must write an algorithm that runs in O(log n) time.
Example 1:
Input: nums = [1,2,3,1]
Output: 2
Explanation: 3 is a peak element and your function should return the index number 2.
Example 2:
Input: nums = [1,2,1,3,5,6,4]
Output: 5
Explanation: Your function can return either index number 1 where the peak element is 2, or index number 5 where the peak element is 6.
Practice link - https://leetcode.com/problems/find-pe...
============================================================
Other playlists in the channel that you can follow:
➡️ Recursion Primer Series - • Recursion Primer Series
➡️ String coding interview questions - • String interview questions
➡️ Arrays Series - • Arrays Series
➡️Linked List Series - • Linked List Series
➡️ Sorting Primer Series - • Sorting primer series
➡️ Binary Search Series - • Binary Search Series
=======================================================
Please click the LIKE button so that this kind of content can be seen by as many as possible aspiring engineers and professionals. Doing so gives me even more motivation to post such content in the future.
Please comment below and let me know if you have any questions or concerns.
Additionally, don't forget to click the bell symbol to receive notifications and subscribe to the channel.
Follow us on:
➡️Twitter - / codeease
----------------------------------------------------------
Created and Instructed by:
Varsha Das
Mid-senior Software Engineer, Content Curator of @Code With Ease
➡️ LinkedIn - / varsha-das-se
➡️ Quora - https://www.quora.com/profile/Varsha-...
➡️ Hashnode - https://varsha-das.hashnode.dev/
➡️ Medium - / varshadas21
Code With Ease is meant to make problem-solving in programming easier. For DSA preparation, we post topic-specific videos pertaining to Coding Interview topics so that everyone may approach such questions with a clear thought process and achieve the best outcomes. In addition, we make an effort to include different "Primer Series" that teach particular concepts or algorithms. We want to be the one-stop solution for everything pertaining to DSA preparation and programming foundations in general, saving candidates from having to visit many sources in order to receive structured content.
Additionally, we believe that learning to code entails much more than only "cracking the coding interview." The long-term goal of this channel is to create more proficient problem-solvers in this field so that, in the end, we can create fantastic products and be able to resolve challenging issues in our environment to improve the quality of life for everyone.
#peakelement #codinginterviewquestion #binarysearch #arraysinjava #binarysearch #divideandconquer