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.
We have to get an average, which is sum(entries)/num(entries). So, ostensibly, we need sum(f(each permutation))/nPn. But the key is to realize that the operations are commutative, associative, and distributive.
So we'll always get the same value S. That means that means our expression reduces to nPn*f(one permutation)/nPn = f(one permutation)
We may as well choose the original permutation. The other thing to help speed up runtime is (a+b)%m = (a%m + b%m)%m
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tell the Average
You are viewing a single comment's thread. Return to all comments →
We have to get an average, which is sum(entries)/num(entries). So, ostensibly, we need sum(f(each permutation))/nPn. But the key is to realize that the operations are commutative, associative, and distributive.
So we'll always get the same value S. That means that means our expression reduces to nPn*f(one permutation)/nPn = f(one permutation)
We may as well choose the original permutation. The other thing to help speed up runtime is (a+b)%m = (a%m + b%m)%m