The following is the solution to Hacker Rank problem Diwali Lights using Java. For solutions to other Hacker Rank Problem visit my page HackerRank, alternatively try searching for the problem in my blog.
The Approach I'm following is given below:
- The problem is easy, if we have 2 bulbs atleast 1 bulb should be set at any time so there are 22-1 possibilities eliminating the condition where all the bulbs are turned off.
- So if we have N bulbs then we have 2N-1 possibilities which is large number to compute.
- We can do this easily with Java's BigInteger , we can calculate the power using pow function.
- Also we must note since this number is large we are asked to print the result mod 105 we can also do this easily with Java's BigInteger mod function.
Read full article from Arun G 's Blog: April 2014
No comments:
Post a Comment