Showing posts with label HackerRank::Algorithms::Combinatorics. Show all posts
Showing posts with label HackerRank::Algorithms::Combinatorics. Show all posts

Friday, April 24, 2015

HackerRank::Algorithms::Combinatorics::Connecting Towns

    Simple, it's a product of all numbers because simple if there are N ways to move from state 1 to state 2 and M ways to move from state 2 to state 3, then there are total N*M ways to move from state 1 to state 3.



HackerRank::Algorithms::Combinatorics::Minimum Draws

   In the worst case we will pull out first N socks on after another with all different colors, and drawing the N+1 th ensures that at least one of them will match because we have already drawn all the possible different colors.


HackerRank::Algorithms::Combinatorics::Handshake

  The first man shakes hands with 2,3...N, total N-1 handshakes, the second man shakes hands with 3,4..,...N total N-2 handshakes, and so on until the N-1 the one shakes hands with only N th one, we have total handshakes equal to 1+2+3+...+N-1 which equals to  ((N-1)* (N))/2