The 128-bit part is what trips you up at first.
Start by clarifying the problem and constraints, then propose an efficient bit-manipulation solution that scans the integer once. Discuss trade-offs between different approaches (e.g., iterative vs. bitwise tricks) and analyze time/space complexity.
Pro tip: Mention that you can use the expression `n & (n << 1)` to detect consecutive 1s, and that the problem can be solved in O(number of 1s) time by repeatedly clearing the lowest set bit. This shows deep bitwise knowledge and efficiency awareness.
Confirm that the integer is 128-bit, that we are looking for the longest run of consecutive 1s in its binary representation, and that the integer may be signed or unsigned. Ask about edge cases like all zeros or all ones.
Explain a simple linear scan: convert to binary string or iterate bit by bit, keeping track of current and maximum run lengths. Mention its O(128) time and O(1) space complexity.
Describe an O(k) approach where k is the number of 1s: repeatedly perform `n = n & (n << 1)` and count iterations until n becomes 0. Each iteration removes the least significant 1 from each consecutive run, effectively reducing the run lengths by 1.
Compare the brute-force and optimized methods: the brute-force is simpler and constant time (128 steps), while the optimized is faster for sparse integers but may be slower for dense ones. Discuss readability vs. performance.
Mention testing with 0, all 1s, alternating bits, and the maximum 128-bit value. Walk through a small example to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.