DEV Community

Rahul kumar
Rahul kumar

Posted on

1

If you are new to dynamic programming

If you are new to dynamic programming, then you should definetly try out this problem.

Problem

Problem description
Alice and Bob take turns playing a game, with Alice starting first.

Try it

Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:

Choosing any
XX
X with
0<X<n0 < X < n
0<X<n and
n%X==0n \% X == 0
n%X==0.

Replacing the number n on the chalkboard with n - x.

Also, if a player cannot make a move, they lose the game.

Return true if and only if Alice wins the game, assuming both players play optimally.

Example 1
Input: n = 2
Output: true
Explanation: Alice chooses 1, and Bob has no more moves.
Exmaple 2
Input: n = 3
Output: false
Explanation: Alice chooses 1, Bob chooses 1, and Alice has no more moves.
Constraints
1<=n<=10001 <= n <= 1000
1<=n<=1000

Try This

Heroku

Built for developers, by developers.

Whether you're building a simple prototype or a business-critical product, Heroku's fully-managed platform gives you the simplest path to delivering apps quickly — using the tools and languages you already love!

Learn More

Top comments (0)

AI Agent image

How to Build an AI Agent with Semantic Kernel (and More!)

Join Developer Advocate Luce Carter for a hands-on tutorial on building an AI-powered dinner recommendation agent. Discover how to integrate Microsoft Semantic Kernel, MongoDB Atlas, C#, and OpenAI for ingredient checks and smart restaurant suggestions.

Watch the video 📺

👋 Kindness is contagious

DEV works best when you're signed in—unlocking a more customized experience with features like dark mode and personalized reading settings!

Okay