Bit at an Index After Repeated Binary Expansion
Updated
Problem statement
Start with a binary string bits. In one expansion round, replace every character independently:
0becomes00.1becomes10.
After exactly rounds expansions, return the bit at the zero-based position index. The position is guaranteed to exist in the expanded string.
Function
expandedBit(bits: String, rounds: int, index: int) → intExamples
Example 1
bits = "01"rounds = 1index = 2return = 1One expansion produces 0010, whose zero-based index 2 contains 1.
Example 2
bits = "1"rounds = 2index = 3return = 0The two expansions are 1 -> 10 -> 1000, and its last bit is 0.
Example 3
bits = "101"rounds = 0index = 2return = 1With zero rounds, query the original string directly.
Constraints
1 <= bits.length <= 10^5bitscontains only0and1.0 <= rounds <= 300 <= index <= 10^9index < bits.length * 2^rounds.
More Amazon Onsite Interview questions
- Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
- Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Evaluate an Arithmetic Expression Written in WordsBrex · PHONE SCREEN
- Integer to English Words in USD and INR StylesVeeam · PHONE SCREEN
- Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Basic Calculator IISnap Inc. · PHONE SCREENSnap Inc. interview questions
- Iterate Canonical IPv6 AddressesOpenAI · ONSITE INTERVIEWOpenAI interview questions
- Nth Staged License PlateGoogle · ONSITE INTERVIEWGoogle interview questions
- Parse a Signed Integer in Any BaseMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Text Embedding and Vector SearchNike, Inc. · PHONE SCREEN · ONSITE INTERVIEWNike, Inc. interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
Amazon interview experiences
- Amazon Experienced SDE Onsite Questions: 1 Experience
- Amazon SDE Onsite Interview Questions: 9 Experiences
- Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
- Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
- Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
- Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)