All Posts

Leetcode 1750: Minimum Length of String After Deleting Similar Ends

You are given a string s consisting of only the characters ‘a’, ‘b’, and ‘c’. Your task is to repeatedly perform the following operation any number of times:

  1. Pick a non-empty prefix from the string where all characters are equal.
  2. Pick a non-empty suffix from the string where all characters are equal.
  3. The prefix and suffix should not intersect, and the characters in both should be the same.
  4. Remove the prefix and suffix.

Your goal is to find the minimum length of the string after performing the operation any number of times.

Leetcode 1754: Largest Merge Of Two Strings

You are given two strings, word1 and word2. You need to construct a string merge by choosing characters from both strings. At each step, you can either append the first character of word1 to merge (if word1 is non-empty) or append the first character of word2 to merge (if word2 is non-empty). The goal is to form the lexicographically largest string possible from these choices.

Leetcode 1764: Form Array by Concatenating Subarrays of Another Array

Given an array of subarrays groups and a single array nums, your task is to determine whether it is possible to extract each subarray from groups as a contiguous segment from nums. The subarrays must appear in the same order as in groups, and they should be disjoint, meaning no element from nums can belong to more than one subarray. Return true if this is possible, and false otherwise.

Leetcode 1768: Merge Strings Alternately

You are given two strings word1 and word2. Merge the two strings by alternating their letters, starting with the first letter of word1. If one string is longer, append the remaining characters of the longer string to the end of the merged string. Return the resulting merged string.

Leetcode 1813: Sentence Similarity III

You are given two sentences, sentence1 and sentence2, which consist of words separated by spaces. Two sentences are considered similar if you can insert any number of words (including none) into one of the sentences to make them identical. The inserted words must be separated by spaces.

Leetcode 1850: Minimum Adjacent Swaps to Reach the Kth Smallest Number

You are given a string num, representing a large integer, and an integer k. Return the minimum number of adjacent swaps required to transform num into the k-th smallest wonderful integer that is greater than num and is a permutation of its digits.