⚡️ Tryprepforge
Coding Round 1 Mid-Level programming

**LeetCode #159 - Longest Substring with At Most Two Distinct Characters**\nGiven a string s, return the length of the longest substring that contains at most two distinct characters. This problem requires an understanding of the sliding window technique to efficiently find the maximum length of the substring under the specified constraint.\n**Function Signature:** `def length_of_longest_substring_two_distinct(s: str) -> int:`\n**Example 1:**\nInput: `s = "eceba"`\nOutput: `3`\nExplanation: The substring is "ece" which contains two distinct characters.\n**Example 2:**\nInput: `s = "aa"`\nOutput: `2`\nExplanation: The substring is "aa" which contains one distinct character.\n**Constraints:**\n- `1 <= s.length <= 10^5`\n- `s` consists of English letters, digits, symbols, and spaces.

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

No credit card required

More Coding Round 1 Interview Prep

Link copied to clipboard