FastPrepBit at an Index After Repeated Binary Expansion
Problems/Bit at an Index After Repeated Binary Expansion

Bit at an Index After Repeated Binary Expansion

Amazon logoAmazon● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time onsite interview. We kept the reported replacements, the starting string, the number of rounds, and the worked example with an indexed query. The example shows that indexing starts at zero. We added limits on the input, since the report did not give the size. Our version is about 98% the same as the reported question.

Start with a binary string bits. In one expansion round, replace every character independently:

  • 0 becomes 00.
  • 1 becomes 10.

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) → int

Examples

Example 1

bits = "01"rounds = 1index = 2return = 1

One expansion produces 0010, whose zero-based index 2 contains 1.

Example 2

bits = "1"rounds = 2index = 3return = 0

The two expansions are 1 -> 10 -> 1000, and its last bit is 0.

Example 3

bits = "101"rounds = 0index = 2return = 1

With zero rounds, query the original string directly.

Constraints

  • 1 <= bits.length <= 10^5
  • bits contains only 0 and 1.
  • 0 <= rounds <= 30
  • 0 <= index <= 10^9
  • index < 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)
See Amazon hiring insights
Saved
class Solution {
    public int expandedBit(String bits, int rounds, int index) {
        // Write your solution here.
    }
}
Checking account…