Find the Longest Subarray with at Most Two Distinct Values

Read the full interview experience this question came from →

Quick Overview

Find the length of the longest contiguous subarray containing no more than two distinct integer values. A correct solution maintains sliding-window invariants across repeated runs, negative values, empty input, and every boundary movement while meeting the linear-time goal.

Find the Longest Subarray with at Most Two Distinct Values

Company: Moody's

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Overview: Find the length of the longest contiguous subarray containing no more than two distinct integer values. A correct solution maintains sliding-window invariants across repeated runs, negative values, empty input, and every boundary movement while meeting the linear-time goal.

Read the full Moody's Software Engineer interview experience this question came from

Moody's logo
Moody's
Jul 25, 2026
mediumSoftware EngineerOnsiteCoding & Algorithms
4
0
Loading...