Ctrl K

Best Order of Binary Pieces

Medium
You are given three positive integers pieces. Write each one in binary (no leading zeros) and join the three strings in some order. The result is the binary form of a new number. Return the largest number you can build this way.
Example 1
pieces=[2, 5, 1] → 54

In binary these are "10", "101" and "1". The order 1, 5, 2 gives "110110" = 54, more than any other order.

Example 2
pieces=[4, 4, 3] → 228

"11" has to go first: "11100100" = 228.

Example 3
pieces=[1, 1, 1] → 7
Constraints
  • len(pieces) = 3
  • 1 ≤ pieces[i] ≤ 127
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPicks With the Full OR MediumOutshoot the Rival MediumColumns That Cover Rows MediumStrongest Product Team MediumMoves Between Offices Hard
loading Python…
Input
pieces=[2, 5, 1]
Expected
54

Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.