All Posts
Leetcode 2038: Remove Colored Pieces if Both Neighbors are the Same Color
colors
consisting of two types of pieces, ‘X’ and ‘Y’, arranged in a line. Two players, Alex and Brian, play a game where they take turns removing pieces from the string. Alex moves first and can only remove a piece ‘X’ if both its neighbors are also ‘X’. Similarly, Brian can only remove a piece ‘Y’ if both its neighbors are also ‘Y’. Neither player can remove edge pieces. If a player cannot make a move, they lose. Determine whether Alex wins the game if both players play optimally.
You are given a string Leetcode 2039: The Time When the Network Becomes Idle
You are managing a network of servers connected by communication channels. One server, labeled as 0, acts as the master server, while the others are data servers. Each data server sends a message to the master server at the start and waits for a reply. The reply travels back via the same route the message took. If a server does not receive a reply within a specific period (defined by its patience value), it resends the message. The goal is to determine when the network will become idle, meaning there are no active messages being transmitted or received.
Leetcode 2043: Simple Bank System
You are required to build a system for a bank that automates various account transactions, including deposits, withdrawals, and transfers. The bank has multiple accounts, and each transaction must adhere to specific rules to be considered valid. Implement a class that handles these operations efficiently while ensuring transactional integrity.
Leetcode 2044: Count Number of Maximum Bitwise-OR Subsets
nums
, find the maximum bitwise OR that can be achieved by any subset of nums
and count how many different non-empty subsets yield this maximum value. A subset is defined as any combination of elements from the array, and subsets are considered different if their elements are selected from different indices.
Given an integer array Leetcode 2048: Next Greater Numerically Balanced Number
An integer x is numerically balanced if, for every digit d in x, the digit d occurs exactly d times in the number. For example, 22 is numerically balanced because the digit 2 appears exactly 2 times, while 3133 is numerically balanced because the digit 3 appears exactly 3 times, and the digit 1 appears exactly 1 time.
Given an integer n, find the smallest numerically balanced integer that is strictly greater than n.
Leetcode 2049: Count Nodes With the Highest Score
You are given a binary tree with n nodes, where each node is labeled from 0 to n-1. The tree is represented by a 0-indexed array parents
, where parents[i]
indicates the parent of node i
. The root node has no parent, so parents[0] == -1
.
Each node has a score, calculated as follows:
- If the node and the edges connected to it are removed, the tree splits into one or more non-empty subtrees.
- The score of a node is the product of the sizes of all resulting subtrees.
Return the number of nodes with the highest score in the tree.