First Register Overflow Tick
Updated
Problem statement
An unsigned bits-bit register initially contains zero. At each unit tick, add the same positive integer increment. The first addition is at tick 1.
Overflow occurs when the mathematical sum would exceed 2^bits - 1. Return the first tick at which overflow occurs. Do not wrap the stored value before deciding whether that tick overflows.
Function
firstOverflowTick(bits: int, increment: int) → longExamples
Example 1
bits = 8increment = 10return = 26Tick 25 would store 250, while tick 26 would store 260 above the maximum 255.
Example 2
bits = 8increment = 255return = 2Tick 1 reaches the valid maximum 255; tick 2 is the first overflow.
Example 3
bits = 4increment = 20return = 1The maximum is 15, so the first addition already overflows.
Constraints
1 <= bits <= 31.1 <= increment <= 10^9.- The result is a positive signed 64-bit integer.
More NVIDIA Onsite Interview questions
- Check Endianness Of A Byte ArrayONSITE INTERVIEW · Seen Sep 2026
- Implement MallocONSITE INTERVIEW · Seen Sep 2026
- Implement PrintfONSITE INTERVIEW · Seen Sep 2026
- Merge Two Arrays Into Sorted OrderONSITE INTERVIEW · Seen Sep 2026
- Middle Node Of A Linked ListONSITE INTERVIEW · Seen Sep 2026
- Ping Reply TrackingONSITE INTERVIEW · Seen Sep 2026
- Reverse A StringONSITE INTERVIEW · Seen Sep 2026
- Maximum Fish in a GridONSITE INTERVIEW · Seen Sep 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Two-Egg DroppingONSITE INTERVIEW · Seen May 2024
Similar questions at other companies
- K-th Amount a Payout Machine Can GiveRippling · ONSITE INTERVIEWRippling interview questions
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Insert into a Left-Complete Binary TreeRubrik · ONSITE INTERVIEWRubrik interview questions
- Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
- Bayesian Scenario ClassifierAmazon · ONSITE INTERVIEW
- Maximum Supplier ProfitExpedia · ONSITE INTERVIEWExpedia interview questions
- Two Eggs: Minimum Worst-Case DropsApple · ONSITE INTERVIEWApple interview questions
- Find a Function Root by BisectionJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Product of Two Integers Without MultiplyingCapital One · ONSITE INTERVIEWCapital One interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW