We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Alice and Bob's Silly Game
Alice and Bob's Silly Game
Sort by
recency
|
54 Discussions
|
Please Login in order to post a comment
Java
JavaScript Solution
Here is Alice and Bob's Silly game problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-alice-and-bobs-silly-game-problem-solution.html
Linear Sieve+Prefix Sums
Here is my simple algorithm to solve the problem. I won't tell the code as so many people here have already done without explaining anything. I created a function which takes int n input and returns total count of prime numbers form 1 to n including. Now, if n is even, answer is "Bob" else it is "Alice". Now this method passes three test cases but time limit exceeds in two other test case. What I observed is that, on single test case, multiple inputs are being taken, so calculating everytime the count of prime numbers is redundant. So, I created some global arrays to store the count and when it repeats, I supply it from there. Reply if you need more explanation or code.