All Posts

Leetcode 3101: Count Alternating Subarrays

You are given a binary array nums. A subarray is called alternating if no two adjacent elements in the subarray have the same value. Return the total number of alternating subarrays in the given binary array.

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 3122: Minimum Number of Operations to Satisfy Conditions

You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. Your task is to perform operations such that each cell is equal to the cell below it, and different from the cell to its right. Return the minimum number of operations needed to achieve these conditions.

Leetcode 3128: Right Triangles

You are given a 2D binary matrix grid, where each element is either 0 or 1. A collection of three elements of the grid is considered a right triangle if one element lies in the same row as another and in the same column as the third. The three elements must not be adjacent to each other. Your task is to count the number of right triangles that can be formed where all three elements have a value of 1.

Leetcode 3129: Find All Possible Stable Binary Arrays I

You are given three positive integers: zero, one, and limit. A binary array is called stable if it satisfies the following conditions:

  1. It contains exactly one occurrence of the number 1.
  2. It contains exactly zero occurrences of the number 0.
  3. Any subarray of size greater than limit must contain both 0 and 1.

Return the total number of stable binary arrays that can be formed. Since the answer can be large, return it modulo 10^9 + 7.

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.