Sort by

recency

|

206 Discussions

|

  • + 0 comments

    The problem here is big integers We would not use big integers if we apply modular ariphmetics (A*B) mod M = (A mod M * B mod M) mod M

    https://www.geeksforgeeks.org/modular-multiplication/ https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/modular-multiplication

    my solution:

    https://github.com/Tusenka/hackerrank/blob/main/bulbs.py

  • + 0 comments

    Python Solution: def lights(n): # Write your code here if n==1: return 1 else: return ((2**n-1)%10**5)

  • + 0 comments

    Draw out the truth table for N inputs and you will see that there is one input where all the values are 0. The rest of the inputs has at least one set bit. that means the answer is (2 ^ N) - 1 and then take the modulus of it.

  • + 0 comments

    Here's my java solution:

    public static long lights(int n) {

        BigInteger ans=(BigInteger.valueOf(2).pow(n).subtract(BigInteger.valueOf(1))).mod(BigInteger.TEN.pow(5));  
    
        return ans.longValue();
    }
    
  • + 0 comments

    it's like sum of combinations.. nC0 + nC1 + nC2 ... +nCk +..nCn = 2^n;

    where "k" is the number of lights at a moment of time. we'll traverse from [0 , n-1] and creating 2^n slowly with limit 1e5

    at last we won't consider the case where no light bulb is ON.

    2^n - nC0 -> 2^n - 1

    let l = 100000;
    
    function lights(n: number): number {
        // Write your code here
        let tot = 1;
        for(let i = 0; i<n; i++){
            tot *= 2;
            tot = tot%l
        }
        return tot-1;
    *  }