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. Handshake

Handshake

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics
  1. Prepare
  2. Mathematics
  3. Fundamentals
  4. Handshake
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Topics

At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there?

Example

There are attendees, , and . shakes hands with and , and shakes hands with . Now they have all shaken hands after handshakes.

Function Description

Complete the handshakes function in the editor below.

handshakes has the following parameter:

  • int n: the number of attendees

Returns

  • int: the number of handshakes

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

0
1

Explanation

Case 1 : The lonely board member shakes no hands, hence 0.
Case 2 : There are 2 board members, so 1 handshake takes place.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy