4 kyu
Count ones in a segment
650 of 3,288d0n14
Description:
Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000) return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both)
Example:
countOnes 4 7 should return 8, because:
4(dec) = 100(bin), which adds 1 to the result.
5(dec) = 101(bin), which adds 2 to the result.
6(dec) = 110(bin), which adds 2 to the result.
7(dec) = 111(bin), which adds 3 to the result.
So finally result equals 8.
WARNING: Segment may contain billion elements, to pass this kata, your solution cannot iterate through all numbers in the segment!
Binary
Performance
Algorithms
Similar Kata:
Stats:
Created | Jul 17, 2017 |
Published | Jul 17, 2017 |
Warriors Trained | 17732 |
Total Skips | 5627 |
Total Code Submissions | 23402 |
Total Times Completed | 3288 |
C++ Completions | 650 |
Haskell Completions | 118 |
JavaScript Completions | 795 |
Python Completions | 1016 |
C Completions | 342 |
NASM Completions | 22 |
Java Completions | 225 |
Forth Completions | 12 |
C# Completions | 154 |
COBOL Completions | 9 |
Go Completions | 40 |
Rust Completions | 71 |
Kotlin Completions | 47 |
Total Stars | 748 |
% of votes with a positive feedback rating | 94% of 515 |
Total "Very Satisfied" Votes | 460 |
Total "Somewhat Satisfied" Votes | 45 |
Total "Not Satisfied" Votes | 10 |
Total Rank Assessments | 8 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |