Approach
No matter how many times operations are taken, the total bit number for the specific position is unchanged.
The k biggest integers can be made from those bits collected from all numbers.
Complexity
Time complexity:
O(31×n+31×k)=O(n+k)O(31×n+31×k)=O(n+k)O(31×n+31×k)=O(n+k)
Space complexity:
O(n)
[x] Added problem & solution under the correct topic.
[x] Specified Space & Time complexity.
[x] Specified difficulty level, tag & Note(if any).
[x] Test Case 1: Input nums = [2,6,5,8], k = 2, Expected Output: 261
[x] Test Case 2: Input nums = [4,5,4,7], k = 3, Expected Output: 90
[x] My code follows the style guidelines of this project
[x] I have performed a self-review of my own code
[x] I have commented my code so that it is easy to understand
[x] I have made corresponding changes to the documentation
[x] My changes generate no new warnings
[x] Any dependent changes have been merged and published in downstream modules
Description
Intuition Counting bits
Approach No matter how many times operations are taken, the total bit number for the specific position is unchanged. The k biggest integers can be made from those bits collected from all numbers.
Complexity Time complexity: O(31×n+31×k)=O(n+k)O(31×n+31×k)=O(n+k)O(31×n+31×k)=O(n+k)
Space complexity: O(n)
[x] Added problem & solution under the correct topic.
[x] Specified Space & Time complexity.
[x] Specified difficulty level, tag & Note(if any).
[x] Test Case 1: Input nums = [2,6,5,8], k = 2, Expected Output: 261
[x] Test Case 2: Input nums = [4,5,4,7], k = 3, Expected Output: 90
[x] My code follows the style guidelines of this project
[x] I have performed a self-review of my own code
[x] I have commented my code so that it is easy to understand
[x] I have made corresponding changes to the documentation
[x] My changes generate no new warnings
[x] Any dependent changes have been merged and published in downstream modules