Skip to main content
All Questions

Find the maximum number of equal-bit pairs in a subsequence of a binary string.

Unlock detailed company stats for this questionUpgrade

Given a binary signal string, choose a subsequence by deleting zero or more characters without changing the order of the remaining characters. Whenever two identical bits appear consecutively in the chosen subsequence (like '00' or '11'), they form an equal-bit pair. Determine the maximum number of equal-bit pairs that can be formed.

Complete getMaxEqualPairs(string signal) -> int. Example: signal = "10101" -> 2 (choose all '1's to form "111", giving pairs at indices 0-1 and 1-2). Sample: input 11011100 -> 5 (subsequence "1111100" yields 5 equal-bit pairs). Constraints: 1 <= length of signal <= 2 * 10^5; the string contains only '0' and '1'.

Format · Amazon SDE Intern OA.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.