Invert Ad Visibility Bits
Updated
Problem statement
An e-commerce platform encodes the current visibility of its advertisements as a positive decimal integer base10. In the integer's binary representation, 1 means an ad is visible and 0 means it is hidden.
On every page load, invert every significant bit, beginning with the highest-order 1 bit and continuing through the rightmost bit:
- Change each
1to0. - Change each
0to1.
Convert the resulting binary value back to decimal and return it.
Implement invertAdVisibility with one parameter, int base10, and return the inverted value as an int.
Function
invertAdVisibility(base10: int) → intExamples
Example 1
base10 = 30return = 1The significant binary representation of 30 is 11110. Flipping all five bits gives 00001, whose decimal value is 1.
Example 2
base10 = 10return = 5The significant bits of 10 are 1010. Their inversion is 0101, which equals 5.
Example 3
base10 = 1return = 0The only significant bit is 1. Flipping it produces 0.
Constraints
base10is a positive integer that fits in a signedint.
More JP Morgan Chase Online Assessment questions
- Find Total CostOA · Seen Oct 2026
- Minimum Meeting RoomsOA · Seen Oct 2026
- Count Dropped RequestsOA · Seen Oct 2026
- Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
- Task SchedulingOA · Seen Oct 2026
- Substring RemovalOA · Seen Oct 2026
- Maximum Game Board ScoreOA · Seen Sep 2026
- Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
- Same Substring Within BudgetOA · Seen Sep 2026
- Maximum of Subarray MinimumsOA · Seen Aug 2026
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 nGEP · OA
- Count Times Using at Most Two DigitsLSEG · OALSEG interview questions
- Minimum Tokens RemainingMicrosoft · OAMicrosoft interview questions
- Minimum Operations to Make Binary PalindromicGoogle · OAGoogle interview questions
- Powers of 2Oracle · OAOracle interview questions
- Find the Lowest Set Bit PositionExpedia · OA · ONSITE INTERVIEWExpedia interview questions
- Knights, Knaves and Their StatementsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Repeated Mirror XORMathWorks · OAMathWorks interview questions
JP Morgan Chase interview experiences
- JPMorgan Chase Experienced SWE Java Interview: 1 Experience
- JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
- JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
- JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
- JP Morgan Chase Data and AI Intern Superday: 11 Experiences
- JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)