Limited Time Offer:Up to 20% off Hello Interview Premium
Up to 20% off Hello Interview Premium 🎉
Hello Interview
Your Dashboard
System Design
Code
Low Level Design
Behavioral
AI Coding
New
ML System Design
Salary Negotiation
Interview Guides
Blog
System Design
Low Level Design
AI Coding
Behavioral
New
Interview Questions
Success Stories
System Design
Low-Level Design
New
Ask The Community
Discord
Mock Interviews
1:1 Mentorship
Refer a Friend
Pricing
Sign in / Sign up
Search
⌘K
Pricing

Tutor

Longest Balanced Substring With One Swap

Given a binary string s, perform at most one swap between any two characters, then select a substring with an equal number of '0's and '1's. Return the maximum length of such a balanced substring.

Asked at:

LinkedIn

LinkedIn


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Company
​
Level
All Regions
Region

Early May, 2026

LinkedIn

LinkedIn

Mid-level

You are given a binary string s consisting only of characters '0' and '1'. A string is balanced if it contains an equal number of '0's and '1's. You can perform at most one swap between any two characters in s. Then, you select a balanced from s. Return an integer representing the maximum length of the balanced substring you can select. Example 1: Input: s = "100001" Output: 4 Explanation: Swap "100001". The string becomes "101000". Select the substring "101000", which is balanced because it has two '0's and two '1's. Example 2: Input: s = "111" Output: 0 Explanation: Choose not to perform any swaps. Select the empty substring, which is balanced because it has zero '0's and zero '1's.

Your account is free and you can post anonymously if you choose.

Hello Interview Premium

Recent interview questions
System Design Guided Practice
Exclusive content
Learn More
Questions
Meta SWE Interview QuestionsAmazon SWE Interview QuestionsGoogle SWE Interview QuestionsOpenAI SWE Interview QuestionsEngineering Manager (EM) Interview Questions
Learn
Learn System DesignLearn DSALearn BehavioralLearn ML System DesignLearn Low Level DesignGuided Practice
Links
FAQPricingGift PremiumHello Interview Premium
Legal
Terms and ConditionsPrivacy PolicySecurity
Contact
About UsProduct Support

7511 Greenwood Ave North Unit #4238 Seattle WA 98103


© 2026 Optick Labs Inc. All rights reserved.