0
I didn't understand how the output will come 240 can you clear my doubt â
Title: The coding Challenges Problem: There are n participants appearing for one on one coding challenge.Each participant plays twice (challenges) with each of his opponents.You need to compute the total number of challenges. Input: First line contains an integer n, represent number of participants. Output: Print the total number of challenges. Constraints: 1â€nâ€100 Sample Input: 16 Sample Output: 240
3 Answers
+ 4
Let's look at a smaller example.
Sample Input: 3
Sample Output: 6
There are 3 participants, A, B, C. Each one of them plays twice against each of their opponnents. The matches are:
A - B
A - B
A - C
A - C
B - C
B - C
Can you work it out for n=16?
+ 5
in python you can do it with 2 nested for loops to generate tuples like this:
(1,2), (1,3),...
keep in mind that equal pairs are not valid e.g. (1,1),...
so finally you get 240 pairs.
a general calculation for the number of pairs is: (n1 + n2 + ... + n15) *2. so result of summation is 120 * 2 = 240.
+ 2
Thaks you #mr Diego
I understood đ