All Posts

Leetcode 1138: Alphabet Board Path

You are given an alphabet board. Starting at position (0, 0), you need to move around the board to form the target string using the minimum number of moves. The allowed moves are ‘U’, ‘D’, ‘L’, ‘R’, and ‘!’ to select the character at the current position.

Leetcode 1139: Largest 1-Bordered Square

Given a 2D grid of 0s and 1s, return the number of elements in the largest square subgrid that has 1s on its border and 0s inside. If no such subgrid exists, return 0.

Leetcode 1140: Stone Game II

Alice and Bob are playing a game with piles of stones. Each pile contains a positive integer number of stones. On each player’s turn, they can take stones from the first X remaining piles, where 1 <= X <= 2M. The goal is to maximize the number of stones Alice can collect assuming both play optimally.

Leetcode 1143: Longest Common Subsequence

Given two strings text1 and text2, return the length of their longest common subsequence. A subsequence is a sequence that can be derived from the string by deleting some characters without changing the order of the remaining characters.

Leetcode 1144: Decrease Elements To Make Array Zigzag

You are given an array nums of integers. A move consists of selecting any element and decreasing it by 1. A zigzag array is an array where either every even-indexed element is greater than its adjacent elements or every odd-indexed element is greater than its adjacent elements. Your task is to return the minimum number of moves required to transform the given array into a zigzag array.

Leetcode 1145: Binary Tree Coloring Game

Two players play a turn-based game on a binary tree. We are given the root of the tree and the number of nodes, n, where n is odd, and each node has a distinct value from 1 to n. Player 1 selects a value x and colors the corresponding node red, while Player 2 selects a value y (where yx) and colors the corresponding node blue. Players take turns coloring neighboring nodes. The game ends when both players pass their turns, and the winner is the player who colored more nodes. Your task is to determine if Player 2 can guarantee a win by choosing a value y.