We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Pairwise Sum and Divide
Pairwise Sum and Divide
Sort by
recency
|
10 Discussions
|
Please Login in order to post a comment
My Python code that passed all test cases:
Note that a,b ≥ 1, so a+b/ab quickly approaches 0. Because we take the floor of the function only a few value pairs will give non-0 results. Experimenting around, you'll see that 1,1 gives 1+1/1*1 = 2/1 = 2 and 1,n | n≥2, yields 1+n/n, which will yield 1 for all values n. Next, 2,2 yields 4/4 = 1, and 2,n yields 2+n/2n = 0 for n ≥ 3.
So, we need 2*nP2 | n = # of 1s, which is 2*n!/(n-2)!2! = 2n(n-1)/2 = n(n-1)
Also, for each 1, each non-1 will yield 1, so with m 1s and n other numbers, we'll need n*m (note than n = len(a)-m).
Lastly, we'll need nP2 | n = # of 2s, which, similar to above = n(n-1)/2
As for coding, I reccommend creating a counter (you could just do an array [m,n], then calculate the necessary values from that and total them.
Test case 11 is not correct rest everything works fine. Any suggestions
Very Simple . We have to care about the only 2 and 1. Because other numbers , like 3,4 will give (3+4)/(3*4)= 0 .So don't care about them .
All one(1) among them , make value 2 because (1+1)/(1*1) = 2.
All one(1) with other numbers, make value 1 because like for 3 (1+3)/(1*3)= 1
All two among them will make 1 . Because for 2 (2+2)/(2*2)=1 .
So only count them and give the result
My solution with comments line
https://github.com/joy-mollick/Problem-Solving-Solutions-Math-Greedy-/blob/master/HackerRank-Pairwise%20Sum%20and%20Divide.cpp
Simple question