All Posts

Leetcode 3081: Replace Question Marks in String to Minimize Its Value

You are given a string s consisting of lowercase English letters and question marks (?). Your task is to replace all occurrences of ? with any lowercase English letter in such a way that the total cost of the resulting string is minimized. The cost of a string is the sum of how many times each character has appeared before its current position. If there are multiple solutions with the same minimal cost, return the lexicographically smallest one.

Leetcode 3110: Score of a String

You are given a string s. The score of a string is defined as the sum of the absolute difference between the ASCII values of adjacent characters. Return the score of the string s.

Leetcode 3120: Count the Number of Special Characters I

You are given a string word. A letter is considered special if it appears both in its lowercase and uppercase form in the string. Return the number of special letters in word.

Leetcode 3121: Count the Number of Special Characters II

You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c. Return the number of special letters in word.

Leetcode 3136: Valid Word

You are given a string word. The word is considered valid if it satisfies the following conditions:

  1. It contains at least 3 characters.
  2. It contains only digits (0-9) and English letters (both uppercase and lowercase).
  3. It must include at least one vowel (‘a’, ’e’, ‘i’, ‘o’, ‘u’ and their uppercase counterparts).
  4. It must include at least one consonant (an English letter that is not a vowel).

Return true if the word is valid, otherwise return false.

Leetcode 3137: Minimum Number of Operations to Make Word K-Periodic

You are given a string word of length n, and an integer k such that k divides n. In one operation, you can pick any two indices i and j, both divisible by k, and swap the substrings starting from i and j, each of length k. The goal is to transform word into a k-periodic string, meaning that the string can be represented as multiple concatenations of a substring of length k. Your task is to determine the minimum number of operations required to make the string k-periodic.