All Posts

Leetcode 2899: Last Visited Integers

Given an integer array nums, where each element is either a positive integer or -1. For each -1, find the respective last visited positive integer. The ’last visited integer’ refers to the most recent positive integer seen before each -1.

Leetcode 2900: Longest Unequal Adjacent Groups Subsequence I

You are given two arrays: words (a list of distinct strings) and groups (a binary array where each element corresponds to an entry in words). Your task is to select the longest alternating subsequence of words, where each consecutive word has a different corresponding group value. For each pair of consecutive words in the subsequence, the corresponding values in groups must be different.

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 2903: Find Indices With Index and Value Difference I

You are given a 0-indexed array of integers nums of length n, along with two integers, indexDifference and valueDifference. Your task is to find two indices i and j such that the difference between the indices is greater than or equal to indexDifference, and the absolute difference between the values at the indices is greater than or equal to valueDifference. Return the indices [i, j] if such a pair exists, otherwise return [-1, -1].

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.