All Posts

Leetcode 1690: Stone Game VII

Alice and Bob are playing a game with a row of n stones. On each player’s turn, they can remove the leftmost or the rightmost stone, and their score is the sum of the remaining stones. Alice tries to maximize the score difference, while Bob aims to minimize it. Calculate the score difference between Alice and Bob when both play optimally.

Leetcode 1716: Calculate Money in Leetcode Bank

Hercy is saving money for his first car. He deposits money into his Leetcode bank account every day. On the first day (Monday), he deposits $1. For every subsequent day from Tuesday to Sunday, he deposits $1 more than the previous day. Every Monday, he increases his deposit by $1 compared to the previous Monday. Given a number n, representing the number of days Hercy saves money, return the total amount of money he has saved after the nth day.

Leetcode 1742: Maximum Number of Balls in a Box

You are working in a ball factory with n balls numbered from lowLimit to highLimit (inclusive). You have an infinite number of boxes numbered from 1 to infinity. Your task is to place each ball into the box where the box number equals the sum of the digits of the ball’s number. For example, a ball numbered 321 will go into box 6 (since 3 + 2 + 1 = 6), and a ball numbered 10 will go into box 1 (since 1 + 0 = 1). The goal is to find the box with the most balls and return the number of balls in that box.

Leetcode 1753: Maximum Score From Removing Stones

You are given three piles of stones, with sizes a, b, and c respectively. In each turn, you can choose two different non-empty piles, remove one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles left, meaning no more valid moves are available. Your task is to return the maximum score you can achieve.

Leetcode 1759: Count Number of Homogenous Substrings

Given a string s consisting of lowercase letters, your task is to find the total number of homogenous substrings in s. A homogenous substring is a substring where all characters are the same. Since the result could be very large, return the total modulo 10^9 + 7.

Leetcode 1806: Minimum Number of Operations to Reinitialize a Permutation

You are given an even integer n and a permutation perm of size n where initially perm[i] = i (0-indexed). In each operation, you create a new array arr based on certain rules and update perm to arr. The goal is to determine the minimum number of operations required to restore perm to its initial state.