BackmediumSliding Window Infosys

Max Consecutive Same Type Solution

Problem Statement

Given an array of integers `fruit_types` representing the types of fruits, determine the maximum number of fruits that can be harvested under the constraint that only fruits of the same type can be picked consecutively.

Example 1
Input
[1, 2, 1, 2, 3, 3, 3]
Output
3

Explanation: The maximum number of fruits that can be harvested consecutively is 3, which are of type 3.

Example 2
Input
[1, 1, 1, 1, 1]
Output
5

Explanation: All 5 fruits are of the same type and can be harvested consecutively.

Constraints

  • 1 <= length of `fruit_types` <= 10^5
  • -10^9 <= `fruit_types[i]` <= 10^9
  • `fruit_types` contains only integers
  • The input array is not empty
  • The input array contains at least one positive integer
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free