Bug Report for https://neetcode.io/problems/longest-consecutive-sequence
The Go compiler does not allow me to use the if statement ( if _, exists := sumMap[num-1]; exists {) which is correct.
func longestConsecutive(nums []int) int {
sumMap := make([]int, len(nums))
maxElement := nums[0]
for num := range nums {
if _, exists := sumMap[num-1]; exists {
sumMap[num] = sumMap[num-1]+1
if sumMap[num] > sumMap[maxElement] {
maxElement = num
}
} else {
sumMap[num] = 1
}
}
return sumMap[maxElement]
}