Bug Report for https://neetcode.io/problems/largest-unique-number
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
While working through this problem I created a stack solution that was accepted:
class Solution:
def largestUniqueNumber(self, nums: List[int]) -> int:
nums_stack = []
nums.sort()
last_num = -1
for num in nums:
if num not in nums_stack:
nums_stack.append(num)
last_num = num
elif num in nums_stack:
nums_stack.pop()
last_num = num
elif num == last_num:
continue
if len(nums_stack) > 0:
return nums_stack[-1]
else:
return -1
This should not be accepted, because odd number groupings cause an append, pop, and append sequence where the number is still added to the stack
Proposing to change a test case where the largest number is a non-distinct odd group.
nums=[5,7,3,9,4,9,8,3,1,9]
or similiar
In this case three 9s would catch this. It passes previously, because any case of odd numbered groups was still lower than the highest distinct number. Passed by luck, but not actually correct.
Bug Report for https://neetcode.io/problems/largest-unique-number
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
While working through this problem I created a stack solution that was accepted:
This should not be accepted, because odd number groupings cause an append, pop, and append sequence where the number is still added to the stack
Proposing to change a test case where the largest number is a non-distinct odd group.
nums=[5,7,3,9,4,9,8,3,1,9]or similiar
In this case three 9s would catch this. It passes previously, because any case of odd numbered groups was still lower than the highest distinct number. Passed by luck, but not actually correct.