Maximum Possible Number by Binary Concatenation - Problem
You are given an array of integers nums of size 3. Return the maximum possible number whose binary representation can be formed by concatenating the binary representation of all elements in nums in some order.
Note that the binary representation of any number does not contain leading zeros.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3]
›
Output:
30
💡 Note:
Binary representations: 1→"1", 2→"10", 3→"11". Optimal arrangement [1,3,2] gives "1"+"11"+"10"="11110" which equals 30 in decimal.
Example 2 — Larger Numbers
$
Input:
nums = [2,8,16]
›
Output:
1619
💡 Note:
Binary: 2→"10", 8→"1000", 16→"10000". Optimal order [8,2,16] gives "1000"+"10"+"10000"="100010100000" = 1619.
Example 3 — Single Digit Focus
$
Input:
nums = [5,6,7]
›
Output:
1774
💡 Note:
Binary: 5→"101", 6→"110", 7→"111". Best arrangement [7,6,5] produces "111"+"110"+"101"="111110101" = 1774.
Constraints
- nums.length == 3
- 1 ≤ nums[i] ≤ 107
Visualization
Tap to expand
Understanding the Visualization
1
Input Numbers
Given array of 3 integers: [1, 2, 3]
2
Convert to Binary
Transform: 1→"1", 2→"10", 3→"11"
3
Find Best Order
Compare concatenations to get maximum: "11110" = 30
Key Takeaway
🎯 Key Insight: Compare binary concatenations to determine optimal ordering for maximum value
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code