Maximum Possible Number by Binary Concatenation - Problem
Binary Puzzle: You're given an array of exactly 3 integers, and your task is to create the largest possible number by concatenating their binary representations in any order you choose.
For example, if you have
Key Points:
For example, if you have
[1, 2, 3], their binary forms are ["1", "10", "11"]. You could arrange them as "11101" (binary) = 29 (decimal), or "11011" (binary) = 27 (decimal). Your goal is to find the arrangement that gives the maximum decimal value.Key Points:
- You must use all 3 numbers exactly once
- Binary representations never have leading zeros
- Return the final result as a decimal integer
Input & Output
example_1.py โ Basic Case
$
Input:
[1, 2, 3]
โบ
Output:
30
๐ก Note:
Binary representations: 1โ"1", 2โ"10", 3โ"11". Best arrangement is [1,3,2] or [3,1,2] giving "11110" = 30 in decimal.
example_2.py โ Larger Numbers
$
Input:
[2, 8, 16]
โบ
Output:
1000108
๐ก Note:
Binary representations: 2โ"10", 8โ"1000", 16โ"10000". Best arrangement is [16,8,2] giving "1000010001" = 529 in decimal.
example_3.py โ Edge Case with Zero
$
Input:
[0, 1, 2]
โบ
Output:
102
๐ก Note:
Binary representations: 0โ"0", 1โ"1", 2โ"10". Best arrangement is [1,0,2] giving "1010" = 10 in decimal.
Visualization
Tap to expand
Understanding the Visualization
1
Binary Conversion
Transform each decimal number into its binary LED pattern
2
Arrangement Testing
Try all 6 possible ways to arrange the 3 binary segments
3
Maximum Selection
Compare all decimal values and select the largest result
Key Takeaway
๐ฏ Key Insight: With only 3 elements, brute force enumeration of all 6 permutations is the optimal solution - no advanced algorithm can do better than O(1) constant time!
Time & Space Complexity
Time Complexity
O(1)
Since we always have exactly 3 elements, we generate exactly 6 permutations, making this constant time
โ Linear Growth
Space Complexity
O(1)
We only store binary strings and intermediate results, with fixed size input
โ Linear Space
Constraints
- nums.length == 3
- 1 โค nums[i] โค 107
- Each number will have a valid binary representation without leading zeros
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code