Binary Linked List to Decimal
Updated
Problem statement
A linked list contains only bits 0 and 1, with the most significant bit at its head. Return the nonnegative decimal value represented by the list.
For this exercise, the runner supplies bits, an array containing the node values in head-to-tail order. Traverse them in that order. Leading zeros are allowed, and an empty list represents 0. This array is a wire representation of the list; node allocation and links are outside the callable contract.
Function
binaryListToDecimal(bits: int[]) → intExamples
Example 1
bits = [1,0,1,1,0]return = 22The bits represent 16+4+2=22, reading the list from head to tail.
Example 2
bits = []return = 0An empty list has no set bits and represents 0.
Constraints
0 <= bits.length <= 300 <= bits[i] <= 1
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
- Invert Ad Visibility BitsOA · Seen Aug 2026
Similar questions at other companies
- Add NumbersCisco · OACisco interview questions
- Add One to a Number Stored in a Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions
- Add Two Numbers IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Subtract Forward-Order Linked-List NumbersMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Add Numbers Stored in Four-Digit ChunksZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
- Add Forward Linked-List Numbers Using RecursionPeopleStrong · PHONE SCREENPeopleStrong interview questions
- Add Two Numbers Stored as Linked ListsCapital One · ONSITE INTERVIEWCapital One interview questions
- Count Valid Square PairsAuxoAI · OA
- Counting Cows by Their LegsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Server InvestmentRippling · OARippling interview questions