Sum of bit differences among all pairs | GeeksforGeeks

  Рет қаралды 16,106

GeeksforGeeks

GeeksforGeeks

Күн бұрын

Пікірлер: 23
@krishrx3
@krishrx3 9 ай бұрын
The intuition behind formula ans+=(count * (n-count) * 2); lets dry run with example [2,4,3,5] lets write it in binary form. 2 (010) 4 (100) 3 (011) 5 (101) lets take last bit(from right) of each number as a,b,c,d respectively so it'll become a->0,b->0,c->1,d->1. at this instance we have 2 set bits(1s) and 2 non set bits(0s). what are the different combinations we could get(01 or 10)? that would be ac ca ad da bc cb bd db the total count is 8. how can we get above answer from formula? In code we are counting total no of set bits, as from example above there are 2 set bits out of total numbers(n),so by subtracting n with no of set bits we'll get no of 0's(n(total length) - count(no of 1's)) the 2 we are multiplying in formula is because from above example we can see(ac ca) both gonna give same answer,so just multiply with 2 to get rid of duplicates. so by applying in formula we'll get ans+=(no of set bits or 1's) * (no of 0's) * 2; ans+=2*2*2 ->8. dry run rest of bits(traverse towards right or left) you'll get the point.
@rishabhratan2925
@rishabhratan2925 4 жыл бұрын
we can read english on our own!
@rb38653
@rb38653 4 жыл бұрын
Can you please explain how the thinking behind count * (n - count) * 2
@dushyantsingh2624
@dushyantsingh2624 4 жыл бұрын
kzbin.info/www/bejne/iKDdY4J7gL6ff6c she explained it well
@NK-yr6cl
@NK-yr6cl 2 жыл бұрын
Lets says x1,x2,x3 are 1 bit numbers, then xor of only different bits is going to produce non-zero result and hence compute product of count & n-count to get all such sums. Multiply it by 2 to make up for ordering, example {x1,x2} & {x2,x1}. Now extrapolate it to N-bit numbers.
@Entertainmentandexplore
@Entertainmentandexplore 4 жыл бұрын
Aise agar office mey samjhaiga next month hatpe resignation lettr aajaiga.
@ASIFAlI-lq4rd
@ASIFAlI-lq4rd Жыл бұрын
isko samjhnbe ke liye bit masking samjhna hoga....
@engineerBabu777
@engineerBabu777 7 жыл бұрын
Whats the Logic behind the Efficient Solution?
@rahuljoshi456
@rahuljoshi456 7 жыл бұрын
Lets say we have 7 Ones and 3 zeros in a column: Number of ways of selecting two numbers from all 10 numbers: 10C2 Number of (1,1) pairs = 7C2 Number of (0,0) pairs = 3C2 Number of (1,0) pairs = 10C2 - 7C2 -3C2 As those pairs can re-arrange among them selves so final solution: (10C2 - 7C2 -3C2)*2 Simply: (n1 + n2)C2 - n1C2 - n2C2 = n1*n2
@LetsBeHuman
@LetsBeHuman 6 жыл бұрын
@@rahuljoshi456 Why are we multiplying by 2 @3:51 ? I don't get it. Please help.
@murike
@murike 6 жыл бұрын
@@LetsBeHuman You multiply it by 2 because of repetitions. Ex when you iterate summing with 2 loops you compute (a[i], a[j]) and (a[j], a[i]) which are equal.
@nagakalyan8195
@nagakalyan8195 5 жыл бұрын
Hi If the input for one test case with two array values of 1 and -6 gives the expected output as 60. Could anyone please explain this?
@sauravgautam1827
@sauravgautam1827 5 жыл бұрын
smjhh mein aaya kyaaaaaaaaaaaaaaaaa!!!!!!!!!!!!!!!
@calmyourmind5617
@calmyourmind5617 2 жыл бұрын
Abe tum log jo likha rahta hai usiko bolke ek video bana dete ho.... Aur koi logic to clearly explain karte hi nahi hoo.. code aur algorithm padke khudse samajh aya to aya barna gaya kam se....
@therock8815
@therock8815 9 ай бұрын
your english is bc
@samiahmadkhan2865
@samiahmadkhan2865 5 жыл бұрын
Not helpful. Need more explanation how you got that formula
@samiahmadkhan2865
@samiahmadkhan2865 5 жыл бұрын
This is what I inferred: We basically keep a count of ith bits set ( assuming 32 bits or 8 bits whatever ), by shifting bit to the left (which is actually 2^i) i.e. which ith bit from (1
@GarvitJain_1
@GarvitJain_1 5 жыл бұрын
I have a better and easier way to do this
@veerabalajayaraj4459
@veerabalajayaraj4459 5 жыл бұрын
how ??
@kulsumkhansla4101
@kulsumkhansla4101 4 жыл бұрын
cd u plz explain....i didnt get this
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 7 МЛН
路飞做的坏事被拆穿了 #路飞#海贼王
00:41
路飞与唐舞桐
Рет қаралды 25 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 26 МЛН
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Bitwise Operators and WHY we use them
8:41
Alex Hyett
Рет қаралды 93 М.
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 2,1 МЛН
15 Years of Software Engineer Knowledge in 1 hour 30 mins
1:30:39
Rahul Pandey
Рет қаралды 38 М.
Twos complement: Negative numbers in binary
13:49
Ben Eater
Рет қаралды 1,2 МЛН
Sum of All Subsets XOR Total - Leetcode 1863 - Python
18:26
NeetCodeIO
Рет қаралды 11 М.
А я думаю что за звук такой знакомый? 😂😂😂
00:15
Денис Кукояка
Рет қаралды 7 МЛН