keshav, thank you for answering.
Ok i did the for i = 4 and i get 6 pairs. but i'm still not able to understand.
being a beginner i find harder to visualise how it works
for (int i=0; i<N; i++)for (int j=i+1; j<N; j++)if (A[i] > A[j])swap( A[i], A[j] );
the second and third step are executed exactly N(N – 1)/2 times i understood why we got N(N-1). Can someone please explain why divide by 2?
isn't it just N(N-1) times only?
I had done my undergraduate in Business Management but because of interest in CS. i enrolled in college for my CS. Its been like 2 months since i'm actively solving problems on hackerrank. I don't know any fany concepts like DP, matrix exponenciation etc... and due to my weak background in math i could not come up with fast algorithms in Contest resulting in Time Limit exceed situation.
Also weakness in Math makes me think that i'm not able to solve the problem. Could you pls say how i can approach this problem of mine?