HackerRank: Maximum Draws

Second round of the fundamental mathematics problems on HackerRank is called Maximum draws.  It asks the following

Jim is off to a party and is searching for a matching pair of socks. His drawer is filled with socks, each pair of a different color. In its worst case scenario, how many socks (x) should Jim remove from his drawer until he finds a matching pair?

Input Format
The first line contains the number of test cases T.
Next T lines contains an integer N which indicates the total pairs of socks present in the drawer.

Output Format
Print the number of Draws (x) Jim makes in the worst case scenario.

To be honest this was an extremely easy solvable problem. In the worst case Jim can draw a number of socks equal to the amount of pairs and have exactly one sock from each pair. The next sock he draws will then always match one of the already drawn socks.

Or in other words the maximum draws is the number of pairs of socks +1.

In python this can be implemented by

def maximumDraws(n):
    return n + 1 

I have for the sake of brevity only included the function which is called to give the answer, instead of including all the input handling as well.

Posted by Kristian

Leave a Reply