Back to Browse

Stone Game IV Leetcode 1510. Dynamic Programming Code C++ + Explanation

2.1K views
Jan 22, 2022
11:17

Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player's turn, that player makes a move consisting of removing any non-zero square number of stones in the pile. Also, if a player cannot make a move, he/she loses the game. Given a positive integer n, return true if and only if Alice wins the game otherwise return false, assuming both players play optimally. Example 1: Input: n = 1 Output: true Explanation: Alice can remove 1 stone winning the game because Bob doesn't have any moves. Example 2: Input: n = 2 Output: false Explanation: Alice can only remove 1 stone, after that Bob removes the last one winning the game (2 - 1 - 0). Example 3: Input: n = 4 Output: true Explanation: n is already a perfect square, Alice can win with one move, removing 4 stones (4 - 0). Check out our other playlists: Dynamic Programming: https://www.youtube.com/playlist?list=PLLT4EuYB4kIY_DWiiFY_TW3Egm9pmZPuS Trees: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZzjDUX5VKsU9ECdIlsOdkd Heaps and Maps: https://www.youtube.com/playlist?list=PLLT4EuYB4kIatB7uwwkTDq9m-KQkD_out Arrays and Maths: https://www.youtube.com/playlist?list=PLLT4EuYB4kIb0G4k2LxdIs2dCaj9vebqC Bit Manipulation: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZGBE71Udl0m68uFxRiMhGS Greedy Algorithms: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZaOVWhgBnQr9w5JxgHAEld Sorting and Searching: https://www.youtube.com/playlist?list=PLLT4EuYB4kIaWgO_-unJeY4huZlP3Uln9 Strings: https://www.youtube.com/playlist?list=PLLT4EuYB4kIah6F-m0v-zfrQKg1G1zAJC Linked Lists: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZp5ApjgO_5K69Jv4GAGUYt Stack and Queues: https://www.youtube.com/playlist?list=PLLT4EuYB4kIY2nfXL0sxzHbDHReuMw_sE Two Pointers: https://www.youtube.com/playlist?list=PLLT4EuYB4kIbclnecGeKq8vmMdaFYdNyu Graphs, BFS, DFS: https://www.youtube.com/playlist?list=PLLT4EuYB4kIb5er32BqvSqnFFxJ0Ciqf7 Backtracking: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZfNt7M9FMfcJEiE5E8pmFL Non- DSA playlists: Probability: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZWrGlLjATLbuX7CRitUrq6 SQL-Basic Join functions: https://www.youtube.com/playlist?list=PLLT4EuYB4kIZZxUKWLLufuviTI4jWhSHN SQL-Basic Aggregate functions: https://www.youtube.com/playlist?list=PLLT4EuYB4kIa5OBKfvrPRZB6tSVcxhVJN

Download

0 formats

No download links available.

Stone Game IV Leetcode 1510. Dynamic Programming Code C++ + Explanation | NatokHD