Longest Subarray with At Most K Distinct

Programming Interview Hard 6 views
Back to Questions

Problem Description

Input provides {x}. Compute length of the longest contiguous subarray that has at most K distinct numbers.

Input Format

First line n K. Second line n integers.

Output Format

One integer maxLen.

Sample Test Case

Input:
7 2 1 2 1 3 4 2 3
Output:
3

Constraints

1

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next