easyArraysPattern: Sequential

Array Element Repeater Solution

Problem Statement

Given an array of integers and a target integer, find the maximum number of consecutive repetitions of the target integer in the array.

Examples

Example 1:
Input:[1, 2, 2, 3, 3, 3, 4, 4, 4, 4] and target = 3
Output:3
Explanation: The target integer 3 appears consecutively 3 times in the array.
Example 2:
Input:[1, 1, 1, 2, 2, 3, 3, 3] and target = 1
Output:3
Explanation: The target integer 1 appears consecutively 3 times in the array.
Example 3:
Input:[1, 2, 3, 4, 5] and target = 6
Output:0
Explanation: The target integer 6 does not appear in the array.

Constraints

  • 1 <= array length <= 1000
  • -10^9 <= array elements <= 10^9
  • -10^9 <= target <= 10^9
Time: O(n) Space: O(1)
Master coding challenges related to Arrays and solve the Array Element Repeater problem optimally.

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.