All Posts

Leetcode 2363: Merge Similar Items

You are given two 2D integer arrays, items1 and items2, each representing a set of items. Each item has a value and a weight. You need to combine both arrays by summing the weights of items with the same value, and return the result as a 2D array, sorted by the item values in ascending order.

Leetcode 2367: Number of Arithmetic Triplets

You are given a strictly increasing array of integers, nums, and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions hold: i < j < k, nums[j] - nums[i] == diff, and nums[k] - nums[j] == diff. Your task is to return the number of unique arithmetic triplets that can be formed from the given array.

Leetcode 2373: Largest Local Values in a Matrix

You are given a square matrix grid of size n x n. Your task is to generate a new matrix maxLocal of size (n - 2) x (n - 2) where each element maxLocal[i][j] represents the largest value from a 3 x 3 submatrix in grid centered at (i + 1, j + 1). In other words, for each element of the new matrix, find the maximum value from its surrounding 3 x 3 region in the original grid.

Leetcode 2379: Minimum Recolors to Get K Consecutive Black Blocks

You are given a string blocks consisting of the characters ‘W’ and ‘B’, where ‘W’ represents a white block and ‘B’ represents a black block. You are also given an integer k representing the desired length of consecutive black blocks. You can recolor white blocks to black in one operation. The task is to determine the minimum number of operations required to ensure there is at least one occurrence of k consecutive black blocks.

Leetcode 2383: Minimum Hours of Training to Win a Competition

You are preparing for a competition where you will face a series of opponents. Each opponent has a specified energy and experience. To defeat an opponent, your energy and experience must both exceed theirs. Before entering the competition, you are allowed to train to improve your energy or experience. For every hour of training, you can either increase your energy or your experience by one. You need to determine the minimum number of training hours required to defeat all the opponents in order.

Leetcode 2389: Longest Subsequence With Limited Sum

You are given an integer array nums of length n and an integer array queries of length m. For each query, return the maximum size of a subsequence that can be selected from nums such that the sum of its elements is less than or equal to the query value. A subsequence is derived by deleting some or no elements from the array while keeping the relative order intact.