Longest Segment with At Most Two Types
Problem statement
Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.
Problem Given a line of candies represented by a 1D sequence candies, where each position has a candy type.
You may pick at most two distinct candy types, and the candies you pick must come from a contiguous segment: starting at some index and moving right, picking adjacent candies one by one.
Examples
Example 1
input = "3\n1 2 1"return = ["3"]The returned string array must match the expected standard output lines for the sample input.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- Worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.