7 kyu

Most-1-bits

Description:

Given a list of integers(can be positive or negative), find the integer with the highest number of 1 bits in its two's complement binary representation.

Example

most_one_bits([[3, 7, 8, 9, 15]) => #Output: 15 (it has 4 '1' bits)

most_one_bits([3, 7, 8, 9, 23, 28]) => #Output: 23 (it has 4 '1' bits)

In case of a tie, return the last integer in the list with the highest number of 1 bits.

most_one_bits([6, 3, 6, 9, 10]) => #Output: 10 (all have 2 '1' bits
but 10 is the last)

Note:

Integers should be represented in 8 bits

For positive numbers, the calculation of 1 bits in the binary representation remains the same but negative integers will have different results.

most_one_bits([-1,-2,-3]) => #Output -1( it has total of 8 '1' bits)

Duplicates

In case of Duplication of integers only the first occurrence will be considered

Example

most_one_bits([85, 120,-23,-15,-23]) =>#Output -15

( first occurrence of -15 is after first occurrence -23)

Input list will Never be empty( [] )

Fundamentals
Bits
Arrays
Lists
Binary

Stats:

CreatedDec 25, 2024
PublishedDec 25, 2024
Warriors Trained124
Total Skips3
Total Code Submissions424
Total Times Completed62
Python Completions62
Total Stars2
% of votes with a positive feedback rating86% of 22
Total "Very Satisfied" Votes17
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes1
Total Rank Assessments17
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • UK-06 Avatar
  • dfhwze Avatar
Ad