← Nagarro questions

Longest substring with at most 2 unique characters

Filed under Nagarro

Given a string `s`, find all longest substrings that contain at most 2 distinct characters. Return a list of all such substrings without duplicates, preserved in their order of first appearance.

You've read your 3 free write-ups

Sign up free to keep reading. Your account opens the first 10 questions of every company.

Related Nagarro questions

Collected from public candidate posts and coding forums. Updated Nov 2026.