Find the Lowest Set Bit Position
Updated
Problem statement
You are given a non-negative integer n. Write n in binary and number its bits from the right: the last bit is at position 1, the bit before it is at position 2, and so on.
Return the position of the rightmost bit that is 1. If n is 0, it has no 1 bit, so return 0.
Function
rightmostSetBit(n: int) → intExamples
Example 1
n = 44return = 344 in binary is 101100. Reading from the right, positions 1 and 2 hold 0, and position 3 holds the first 1, so the answer is 3.
Example 2
n = 97return = 197 in binary is 1100001. It is odd, so its last bit, at position 1, is already 1.
Example 3
n = 655360return = 18655360 is 10 × 2^16, so in binary it is 1010 followed by sixteen 0s. The lowest 1 of 1010 moves up by 16 places, from position 2 to position 18.
Constraints
0 <= n <= 10^9
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Minimum Testers to Find the Poisoned BottleWalleye Capital · OA
- Address on Same PageNVIDIA · OANVIDIA interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Find the Missing Number from 1 to nGEP · OA
- Invert Ad Visibility BitsJP Morgan Chase · OAJP Morgan Chase interview questions
- Swap Two Integers Without a Temporary VariableOracle · ONSITE INTERVIEWOracle interview questions
- Add Two Binary StringsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Add BinaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Count Times Using at Most Two DigitsLSEG · OALSEG interview questions
- Check Whether a Byte Is NonzeroZscaler · ONSITE INTERVIEWZscaler interview questions
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)