Sort by

recency

|

336 Discussions

|

  • + 0 comments

    For Python3 Platform

    Mathematics Logic - Using combinations. Here it is nc2 = n*(n-1)/2

    I wrote the code from scratch just to get more practice
    def handshakes(n):
        return (n*(n-1))//2
    
    t = int(input())
    for i in range(t):
        n = int(input())
        
        result = handshakes(n)
        
        print(result)
    
  • + 1 comment

    Yes, the formula n * (n - 1) / 2 works perfectly for this. It’s just the classic combination logic (C(n, 2)). If anyone’s looking for a simple breakdown of similar problem-solving patterns, you can click here for a quick resource I found useful.

  • + 1 comment

    Code belove or above most likly will give an error.

    Coz Test Case will force you to cast answer to int before return

  • + 0 comments

    BRO! Its just a simple Combination Formula for C(N, 2) = N! / 2( N - 2)! = N ( N -1 )/2

    int handshakes(int n) {
        return n * (n - 1) / 2;
    }
    

    You nailed it, happy coding 😍

  • + 1 comment

    Java 15

        public static int handshake(int n) {
            if (n < 2) {
                return 0;
            }
            return (n * (n - 1)) / 2;
        }