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.
@rishabhratan29254 жыл бұрын
we can read english on our own!
@rb386534 жыл бұрын
Can you please explain how the thinking behind count * (n - count) * 2
@dushyantsingh26244 жыл бұрын
kzbin.info/www/bejne/iKDdY4J7gL6ff6c she explained it well
@NK-yr6cl2 жыл бұрын
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.
@Entertainmentandexplore4 жыл бұрын
Aise agar office mey samjhaiga next month hatpe resignation lettr aajaiga.
@ASIFAlI-lq4rd Жыл бұрын
isko samjhnbe ke liye bit masking samjhna hoga....
@engineerBabu7777 жыл бұрын
Whats the Logic behind the Efficient Solution?
@rahuljoshi4567 жыл бұрын
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
@LetsBeHuman6 жыл бұрын
@@rahuljoshi456 Why are we multiplying by 2 @3:51 ? I don't get it. Please help.
@murike6 жыл бұрын
@@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.
@nagakalyan81955 жыл бұрын
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?
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....
@therock88159 ай бұрын
your english is bc
@samiahmadkhan28655 жыл бұрын
Not helpful. Need more explanation how you got that formula
@samiahmadkhan28655 жыл бұрын
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