-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Description
LeetCode Username
forbbi
Problem Number, Title, and Link
https://leetcode.com/problems/find-peak-element/description/
Bug Category
Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)
Bug Description
there is a test case in which binary search solution will not work .
Language Used for Code
C++
Code used for Submit/Run operation
class Solution {
public:
int findPeakElement(vector<int>& nums) {
int low=0;
int n=nums.size();
int high=nums.size()-1;
int mid;
while(high>=low){
mid=(high+low)/2;
if(mid!=low&&mid!=high&&nums[mid-1]<nums[mid]&&nums[mid]>nums[mid+1]){
return mid;
}else {
if(mid==low&&mid==high){
return low;
}else if(mid==high&&nums[mid]>nums[mid-1]){
return high;
}else if(mid==low&&nums[mid]>nums[mid+1])
return low;
}
if(nums[mid]<nums[mid+1]){
low=mid+1;
}else{
high=mid-1;
}
}
return low;
}
};Expected behavior
all cases passed but there exists a test case in which it should not pass like e.g : 1,1,1,1,1,1,1,1,2 for this array it will not find correct peak which is 2 . So this case test case should be present for question.
Screenshots
No response
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels