-
Notifications
You must be signed in to change notification settings - Fork 382
Description
LeetCode Username
naXa777
Problem number, title, and link
1207. Unique Number of Occurrences
Category of the bug
- Problem description
- Solved examples
- Problem constraints
- Problem hints
- Incorrect or missing "Related Topics"
- Incorrect test Case (Output of test case is incorrect as per the problem statement)
- Missing test Case (Incorrect/Inefficient Code getting accepted because of missing test cases)
- Editorial
- Programming language support
Description of the bug
Incorrect Code getting accepted. The code AC submission link is https://leetcode.com/problems/unique-number-of-occurrences/submissions/1148757302/
In my code I use UByteArray. UByte values are in range 0..255. If test input contains a number repeated 256 or more times, byte overflow happens. That's why my code is incorrect.
Language used for code
Kotlin
Code used for Submit/Run operation
class Solution {
fun uniqueOccurrences(arr: IntArray): Boolean {
val frequencies = UByteArray(2000)
for (n in arr) {
++frequencies[n + 1000]
}
val uniq = BooleanArray(2000)
for (i in 0 until 2000) {
val freq = frequencies[i].toInt()
if (freq == 0) continue
if (uniq[freq]) return false
uniq[freq] = true
}
return true
}
}Expected behavior
Incorrect Code is rejected by test.
Screenshots
Additional context
Please add a test with this input:
[1,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257,257]
