
Asked in Snapdeal
Count Set Bits Problem Statement
Given a positive integer N
, find the total number of '1's in the binary representation of all the numbers from 1 to N
.
You should return the result modulo 109+7 as the count can be large.
Input:
The first line contains an integer ‘T’ representing the number of test cases.
Each of the next ‘T’ lines contains a single integer ‘N’.
Output:
For each test case, output a single integer which is the count of set bits in the binary representation of all numbers from 1 to N, modulo 109+7.
Each test case's output should be printed on a new line.
Example:
Suppose T
= 2 with the following test cases:
Test case 1:
N = 3
Test case 2:
N = 5
Output:
Test case 1 output:
4
Test case 2 output:
7
Explanation:
For test case 1, numbers are 1, 10, and 11 in binary, with a total of 4 set bits.
For test case 2, numbers are 1, 10, 11, 100, and 101, totaling 7 set bits.
Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 109
- Time limit of 1 second

AnswerBot
4mo
Count the total number of set bits in the binary representation of numbers from 1 to N, modulo 10^9+7.
Iterate through numbers from 1 to N and count the set bits in their binary representation
Use bitwi...read more
Help your peers!
Add answer anonymously...
Top Business Analyst Interview Questions Asked at Snapdeal
Q. How would you improve the health of a marketplace?
Q. How would you design a new customer support system?
Q. What are your short-term and long-term goals?
Interview Questions Asked to Business Analyst at Other Companies
Top Skill-Based Questions for Snapdeal Business Analyst
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Agile Methodology Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Agile Interview Questions and Answers
50 Questions
SDLC Interview Questions and Answers
50 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

