Sort by

recency

|

17 Discussions

|

  • + 0 comments

    I was working on this interesting game problem where Animesh and Mohit select balls and compute the difference between the maximum and minimum ball numbers from each draw. After computing all possible selections, I had to sum up the differences and output the result modulo a number. This required a lot of calculations, but then I remembered CalculatorAdam! It’s the world’s number one calculator website and made it so much easier to handle such calculations. Whether it's for games, finance, or any other complex math, CalculatorAdam is definitely a one-stop destination to simplify your life!

  • + 0 comments

    Precalculate number of ways to form subsets with n as minimum/maximum for valid n.

    Use of (n+1)Cr = nCr * (n+1)/(n+1-r) for efficient calculation of nCr for incrementing n and fixed r

    O(n) solution

    def solve(balls, k): MOD = 10**9+7 result = 0 n = len(balls) balls.sort()

    memo = {}
    memo[k-1] = math.comb(k-1, k-1)
    for i in range(k, n+1):
        memo[i] = memo[i-1] * i // (i-(k-1))
    for i in range(n-k+1):
        result -= balls[i] * memo[n-1-i]
    for i in range(k-1, n):
        result += balls[i] * memo[i]
    return result % MOD
    
  • + 0 comments

    Hi everyone, I get TLE for the last 4 test cases... please advise me on how to optimize the code. Thank you!

    >

    mod = 10**9 + 7 def solve(balls, k): if k == 1: return 0

    balls.sort()
    ans = 0
    n = len(balls)
    
    for i, ball in enumerate(balls):
        if i >= k-1:
            ans += ball * (comb(i, k-1))
    
        if i < n-k+1:
            ans -= ball * comb(n-i-1, k-1)
    
    return ans % mod
    
  • + 0 comments

    I am running a scholarships website for international students on wordpress. Can I use this,"Choose and Calculate" functions in my website for smooth and easy data input?

  • + 0 comments

    have coded the following (naive) O(n^2) solution code below. (Sorry HackerRank people for posting code, I'll not do it again :-) ) It passes only a few test cases and times out as I expected on others. Can anyone see a problem with the logic?