All Posts

Leetcode 2375: Construct Smallest Number From DI String

You are given a string pattern consisting of the characters ‘I’ and ‘D’, where ‘I’ indicates that the next number in a sequence should be greater, and ‘D’ means the next number should be smaller. You need to construct the lexicographically smallest string num of length n + 1 such that the digits in num follow the conditions set by the pattern. The digits in num must be distinct and range from ‘1’ to ‘9’.

Leetcode 2379: Minimum Recolors to Get K Consecutive Black Blocks

You are given a string blocks consisting of the characters ‘W’ and ‘B’, where ‘W’ represents a white block and ‘B’ represents a black block. You are also given an integer k representing the desired length of consecutive black blocks. You can recolor white blocks to black in one operation. The task is to determine the minimum number of operations required to ensure there is at least one occurrence of k consecutive black blocks.

Leetcode 2380: Time Needed to Rearrange a Binary String

You are given a binary string s. In one second, all occurrences of the substring ‘01’ are simultaneously replaced with ‘10’. This process repeats until no occurrences of ‘01’ exist in the string. The task is to return the number of seconds required to complete this process.

Leetcode 2381: Shifting Letters II

You are given a string s consisting of lowercase English letters and a 2D array shifts. Each entry in the array represents a shift operation, where a segment of the string from starti to endi (inclusive) is shifted forward if directioni is 1, or backward if directioni is 0. A forward shift means replacing a character with the next letter in the alphabet (wrapping around from ‘z’ to ‘a’), and a backward shift means replacing a character with the previous letter (wrapping around from ‘a’ to ‘z’). You need to return the final string after all shifts are applied.

Leetcode 2384: Largest Palindromic Number

You are given a string num consisting only of digits. Your task is to form the largest possible palindromic number by rearranging the digits of num. The resulting number should not have leading zeros and must use at least one digit from the string.

Leetcode 2390: Removing Stars From a String

You are given a string s that contains lowercase English letters and stars (*). In each operation, you can choose a star in s, remove the closest non-star character to its left, and remove the star itself. Perform this operation until all stars are removed and return the resulting string.