1

PROBLEM OF THE DAY : 01/03/2024 | Peak element

 6 months ago
source link: https://www.geeksforgeeks.org/videos/problem-of-the-day-01032024-peak-element/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PROBLEM OF THE DAY : 01/03/2024

March 02, 2024 |1.2K Views
PROBLEM OF THE DAY : 01/03/2024 | Peak element
Problem of the Day, Data Structures and Algorithms, binary-search
 Save  Share  3 Likes
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Binary Search but also build up problem-solving skills.

In this problem, we are given a 0-indexed array of integers arr[] of size n, to find its peak element. An element is considered to be peak if it's value is greater than or equal to the values of its adjacent elements (if they exist). The array is guaranteed to be in ascending order before the peak element and in descending order after it.

Note: The output will be 1 if the index returned by your function is correct; otherwise, it will be 0.

Example :

Input: 
n = 3
arr[] = {1, 2, 3}
Peak Element's Index: 2
Output: 1
Explanation: 
If the index returned is 2, then the output printed will be 1. Since arr[2] = 3 is greater than its adjacent elements, and there is no element after it, we can consider it as a peak element. No other index satisfies the same property.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems-preview/peak-element/1

Read More

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK