This is due to the combination formula, n!/r!(n-r)!. where “val” is “n” the number of objects in a set and “r” is 2 since we’re making pairs. So val!/2!(val-2)! = val(val-1)/2.
Great video! But was the if(val > 1) necessary at the end? Because if it 1, it'll just multiply by zero and it'll continue to work. Or did you do it for efficiency?
Hi why is the permuation for no of k anagram = (n -1)*k/2
This is due to the combination formula, n!/r!(n-r)!. where “val” is “n” the number of objects in a set and “r” is 2 since we’re making pairs. So val!/2!(val-2)! = val(val-1)/2.
You explain really well. 👏
Thank you! Glad to help!
Great video! But was the if(val > 1) necessary at the end? Because if it 1, it'll just multiply by zero and it'll continue to work. Or did you do it for efficiency?
It would still work without the check, it’s just there to make the code more efficient, and makes the logic a little more clear in my opinion
I found the same number by doing this,
sum(1 +....+ (value-1))