All Posts
Leetcode 2011: Final Value of Variable After Performing Operations
In a simplified programming language, there are only four operations: incrementing or decrementing a variable X by 1. You are given a list of operations that can either increment or decrement the value of X. Your task is to determine the final value of X after applying all the operations.
Leetcode 2023: Number of Pairs of Strings With Concatenation Equal to Target
You are given an array of digit strings nums and a target digit string target. Count the number of valid pairs of indices (i, j) where i != j such that the concatenation of nums[i] and nums[j] equals target.
Leetcode 2024: Maximize the Confusion of an Exam
You are given a string answerKey where each character represents a question’s answer (either ‘T’ for True or ‘F’ for False), and an integer k. You are allowed to change at most k answers. Your task is to find the maximum number of consecutive ‘T’s or ‘F’s in the string after performing at most k changes.
Leetcode 2027: Minimum Moves to Convert String
You are given a string s consisting of n characters, where each character is either ‘X’ or ‘O’. A move consists of selecting three consecutive characters in the string and converting them all to ‘O’. If a character is already ‘O’, it remains unchanged. Determine the minimum number of moves required to convert all the characters of s to ‘O’.
Leetcode 2038: Remove Colored Pieces if Both Neighbors are the Same Color
You are given a string 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.
Leetcode 2047: Number of Valid Words in a Sentence
A sentence consists of lowercase letters (‘a’ to ‘z’), digits (‘0’ to ‘9’), hyphens (’-’), punctuation marks (’!’, ‘.’, and ‘,’), and spaces (’ ‘) only. A token is any sequence of characters separated by spaces. A token is considered a valid word if all the following conditions are met:
- It does not contain any digits.
- It contains at most one hyphen (’-’), and if present, the hyphen must be surrounded by lowercase letters.
- It contains at most one punctuation mark, and if present, the punctuation mark must be at the end of the token.
Given a sentence, count the number of tokens that are valid words.