Skip to content

Missing Test Case - 162. Find Peak Element #25497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kesavan22 opened this issue Nov 23, 2024 · 1 comment
Closed

Missing Test Case - 162. Find Peak Element #25497

kesavan22 opened this issue Nov 23, 2024 · 1 comment

Comments

@kesavan22
Copy link

LeetCode Username

Kesavan Ramalingam

Problem Number, Title, and Link

  1. Find Peak Element

Bug Category

Incorrect test case (Output of test case is incorrect as per the problem statement)

Bug Description

Test Case passing for Incorrect Peak.

Given Array = [1,10,2000,1,4,5,8,9,10]

The Peak is 2000, but Test Case accepting answer for 10 (8th Index)

Language Used for Code

Java

Code used for Submit/Run operation

class Solution {
    public int findPeakElement(int[] arr) {
        int start = 0;
        int end = arr.length - 1;

        while (start < end) {
            int mid = start + (end - start) / 2;
            if (arr[mid] > arr[mid+1]) {
                end = mid;
            } else {
                // you are in asc part of array
                start = mid + 1; // because we know that mid+1 element > mid element
            }
        }
        return start;
    }
}

Expected behavior

The Peak should be 2000, not 10

Screenshots

image

Additional context

No response

Copy link

LeetCode Support commented: Hello Kesavan Ramalingam,

Thank you for reaching out regarding the issue you're facing with the "Find Peak Element" problem. After reviewing the problem statement, it appears that the function's behavior aligns with the requirements. The problem states that you may return the index of any peak element. Since your test case [1,10,2000,1,4,5,8,9,10] has multiple peaks (including both 2000 and 10), the function's return value of the index of 10 is valid according to the problem's rules.

I recommend revisiting the problem statement to ensure full alignment with its requirements. If you have any further questions or need more clarification, please don't hesitate to reach out.

Best regards,
LeetCode Support Team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant