- Practice
- Mathematics
- Fundamentals
- Handshake
- Discussions

# Handshake

# Handshake

DocFarren + 2 comments Try this reasoning:

I (PersonA) am one out of N people, so I need to shake hands with (N-1) people. This reasoning holds true for all of the N people, so the number of hand shakes is N * (N-1). Now that PersonA and PersonB shook hands, PersonB and PersonA (same people, but from PersonB's perspective) don't need to shake anymore. So we initially counted each combination twice. Therefore, the number of hand shakes is

nShakes = (N * (N-1)) / 2

Din96_Boy + 1 comment Thank you

mattykolej + 0 comments Thank you a lot for this information! I would be very interesting to know about this website a little bit closer. I like using such resources. It helps me to train my flirt skills because I want to impress one girl. I usually use https://www.Iwantdating.com because there is a wide choice of people.

gozoncloddaniel + 0 comments This is what I was thinking about -- the gauss formula!

PPMBrouwers + 1 comment In an example of 4 people: The first person can shake hands with all the others (N-1)=3. The seconds person can shake hands with all the others, without 1: (N-1-1)=2, third = (N-1-1-1)=1, fourth = (N-1-1-1-1)=0. Hence we get exactly range(4) [at least in Python]. So if we do

sum(range(N))

0+1+2+3 == 6, we get the total number of handshakes.

stephen_berks056 + 0 comments That's brief, but it runs in linear time. You can do it in constant time with (N-1) * N // 2.

rajeevpodar + 1 comment Smallest Code written in HackerRank so far:

`return ((n-1)*n) /2;`

arshuoffl + 0 comments Check out "Maximum Draws" answer LoL!

afando + 1 comment It is a standard combinatorics problem. You need to select a pair of people from N people. How many different pairs are there? N choose 2. N! / ((N-2)! * 2!) which simplifies to (N * (N-1)) / 2.

amani_kilumanga + 1 comment I believe one of your exclamation points is misplaced.

N! / (R!(N - R)!) = N! / (2!(N - 2)!)

afando + 0 comments Thanks, edited!

alayek + 1 comment I have a qualm with the sample test cases provided. Don't use 0 or 1, because most of the times they represent some boundary case or special case.

Maybe you can include one example with a bigger number, like 4 or 5?

aryaman_arora201 + 0 comments If you use the most efficient solution, 0 and 1 are not boundary cases (hint hint)

Sort 174 Discussions, By:

Please Login in order to post a comment