All Posts

Leetcode 2901: Longest Unequal Adjacent Groups Subsequence II

You are given an array of strings words and an array groups of equal length n. The task is to find the longest subsequence from words such that the corresponding elements in groups are unequal for adjacent elements in the subsequence, and the Hamming distance between consecutive strings in the subsequence is exactly 1. A string’s Hamming distance with another string is the number of positions at which their characters differ. The subsequence should be returned as an array of strings in the order of the subsequence indices.

Leetcode 2904: Shortest and Lexicographically Smallest Beautiful String

You are given a binary string s and a positive integer k. A substring of s is considered ‘beautiful’ if it contains exactly k occurrences of ‘1’. Your task is to return the lexicographically smallest substring of the shortest length that has exactly k ‘1’s. If no such substring exists, return an empty string.

Leetcode 2905: Find Indices With Index and Value Difference II

You are given an integer array nums of size n, an integer indexDifference, and an integer valueDifference. Your task is to find two indices i and j that satisfy the following conditions:

  • abs(i - j) >= indexDifference,
  • abs(nums[i] - nums[j]) >= valueDifference.

Return the indices [i, j] if such a pair exists, or [-1, -1] if no such pair exists. If there are multiple pairs, any valid pair is acceptable.

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 2909: Minimum Sum of Mountain Triplets II

You are given an array of integers called nums. A mountain triplet consists of three indices (i, j, k) such that i < j < k, nums[i] < nums[j], and nums[k] < nums[j]. Your task is to return the minimum possible sum of any such mountain triplet. If no such triplet exists, return -1.

Leetcode 2910: Minimum Number of Groups to Create a Valid Assignment

You are given a collection of balls, each marked with a number. Your task is to sort the balls into boxes in a way that follows two rules: Balls with the same number must be placed in the same box, but if there are multiple balls with the same number, they can be placed in different boxes. Additionally, the biggest box can only have one more ball than the smallest box. Return the fewest number of boxes required to sort these balls while following these rules.