Skip to content

Practice Most Frequent Number Following Key In an Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2190
LeetCode Problem

Most Frequent Number Following Key In an Array

Problem Statement

You are given a 0-indexed integer array nums. You are also given an integer key, which is present in nums. For every unique integer target in nums, count the number of times target immediately follows an occurrence of key in nums. In other words, count the number of indices i such that: Return the target with the maximum count. The test cases will be generated such that the target with maximum count is unique.

Source: Most Frequent Number Following Key In an Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,100,200,1,100], key = 1
Output
100

# Example 2

Input
nums = [2,2,2,2,3], key = 2
Output
2

Constraints

2 <= nums.length <= 1000
1 <= nums[i] <= 1000
The test cases will be generated such that the answer is unique.

Related LeetCode Problems

Practice more problems similar to Most Frequent Number Following Key In an Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.