You are viewing a single comment's thread. Return to all 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; * }
Seems like cookies are disabled on this browser, please enable them to open this website
Diwali Lights
You are viewing a single comment's thread. Return to all 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