Skip to content
We areTOP 1%

AND, OR and square sum

MediumRating 1700CodeforcesBit Manipulation
Solve on Codeforces(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

The operation never changes how many numbers have each bit set; it only moves bits between numbers. Count bits per position and greedily build each new number from every bit that still has supply.

More in Bit Manipulation

Bit Manipulation questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Single Number IILeetCodeMedium Solve Single Number II on LeetCode (opens in a new tab)
2Single Number IIILeetCodeMedium Solve Single Number III on LeetCode (opens in a new tab)
3Bitwise AND of Numbers RangeLeetCodeMedium Solve Bitwise AND of Numbers Range on LeetCode (opens in a new tab)
4Total Hamming DistanceLeetCodeMedium Solve Total Hamming Distance on LeetCode (opens in a new tab)
5Find the Longest Substring Containing Vowels in Even CountsLeetCodeMedium Solve Find the Longest Substring Containing Vowels in Even Counts on LeetCode (opens in a new tab)
6AGAGA XOOORRRCodeforcesMedium 1500Solve AGAGA XOOORRR on Codeforces (opens in a new tab)
7Data Structures FanCodeforcesMedium 1500Solve Data Structures Fan on Codeforces (opens in a new tab)
8Boboniu and Bit OperationsCodeforcesMedium 1600Solve Boboniu and Bit Operations on Codeforces (opens in a new tab)
9Bitwise ORs of SubarraysLeetCodeMedium Solve Bitwise ORs of Subarrays on LeetCode (opens in a new tab)
10AND, OR and square sumCodeforcesMedium 1700Solve AND, OR and square sum on Codeforces (opens in a new tab)
11Little Girl and Maximum XORCodeforcesMedium 1700Solve Little Girl and Maximum XOR on Codeforces (opens in a new tab)
12BitsCodeforcesMedium 1700Solve Bits on Codeforces (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account