-
Notifications
You must be signed in to change notification settings - Fork 380
Closed
Description
LeetCode Username
Aashish2060
Problem Number, Title, and Link
- Next Greater Element I https://leetcode.com/problems/next-greater-element-i/
Bug Category
Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)
Bug Description
Bug Description
The problem is missing a specific edge test case where the output is not being handled correctly. The case involves arrays with duplicate values and decreasing sequences, which exposes a flaw in certain accepted solutions. Without this test case, some incorrect submissions are still accepted.
Language Used for Code
None
Code used for Submit/Run operation
class Solution:
def nextGreaterElement(self, nums1: List[int], nums2: List[int]) -> List[int]:
res = []
for num in nums1:
idx = nums2.index(num)
next_greater = -1
for j in range(idx+1, len(nums2)):
if nums2[j] > num:
next_greater = nums2[j]
break
res.append(next_greater)
return res
Expected behavior
Input:
nums1 = [2,4]
nums2 = [1,2,3,4]
Expected Output:
[3, -1]
But some solutions incorrectly output:
[3, 3]
Screenshots
No response
Additional context
The missing test case allows inefficient or incorrect logic to pass. Adding this test case will ensure only valid solutions are accepted.
Metadata
Metadata
Assignees
Labels
No labels