2190. Most Frequent Number Following Key In an Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2190

class Solution:
    def mostFrequent(self, nums: List[int], key: int) -> int:
        cnt = Counter()
        res = mx = 0
        for a, b in pairwise(nums):
            if a == key:
                cnt[b] += 1
                if mx < cnt[b]:
                    mx = cnt[b]
                    res = b
        return res