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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Fundamentals
  4. Maximum Draws

Maximum Draws

Problem
Submissions
Leaderboard
Discussions
Editorial

A person is getting ready to leave and needs a pair of matching socks. If there are colors of socks in the drawer, how many socks need to be removed to be certain of having a matching pair?

Example

There are colors of socks in the drawer. If they remove socks, they may not match. The minimum number to insure success is .

Function Description

Complete the maximumDraws function in the editor below.

maximumDraws has the following parameter:

  • int n: the number of colors of socks

Returns

  • int: the minimum number of socks to remove to guarantee a matching pair.

Input Format
The first line contains the number of test cases, .
Each of the following lines contains an integer .

Constraints

Sample Input

2
1
2

Sample Output

2
3

Explanation
Case 1 : Only 1 color of sock is in the drawer. Any will match.
Case 2 : 2 colors of socks are in the drawer. The first two removed may not match. At least socks need to be removed to guarantee success.

Author

shashank21j

Difficulty

Easy

Max Score

5

Submitted By

109610

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy