All Posts

Leetcode 2906: Construct Product Matrix

You are given a 2D integer matrix grid of size n * m. Your task is to calculate a new 2D matrix p of the same size, where each element p[i][j] is the product of all elements in grid except for grid[i][j]. The result for each element should be taken modulo 12345.

Leetcode 2947: Count Beautiful Substrings I

You are given a string s and a positive integer k. A string is beautiful if it satisfies the conditions that the number of vowels equals the number of consonants, and the product of the number of vowels and consonants is divisible by k. Return the number of non-empty beautiful substrings in the string.

Leetcode 2971: Find Polygon With the Largest Perimeter

You are given an array nums consisting of positive integers. A polygon can be formed from the integers if it satisfies the following condition: the sum of the lengths of any k-1 sides must be greater than the length of the remaining side. The perimeter of a polygon is the sum of the lengths of its sides. Your task is to find the largest possible perimeter of a polygon that can be formed using the sides from nums, or return -1 if it is not possible to form such a polygon.

Leetcode 3026: Maximum Good Subarray Sum

You are given an array nums of length n and a positive integer k. A subarray is called good if the absolute difference between its first and last element is exactly k. The task is to return the maximum sum of any good subarray of nums. If no such subarray exists, return 0.

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 3179: Find the N-th Value After K Seconds

You are given two integers, n and k. Initially, you have an array a of size n, where each element is initialized to 1. After each second, every element in the array is updated to be the sum of all preceding elements plus the element itself. The process repeats for k seconds. You need to return the value of the last element of the array, a[n - 1], after k seconds. Since the result may be very large, return it modulo (10^9 + 7).