All Posts

Leetcode 2563: Count the Number of Fair Pairs

Given an integer array nums of size n and two integers lower and upper, find the number of fair pairs. A pair (i, j) is considered fair if it satisfies the following conditions:

  • 0 <= i < j < n
  • lower <= nums[i] + nums[j] <= upper

Return the number of such pairs.

Leetcode 2570: Merge Two 2D Arrays by Summing Values

You are given two 2D integer arrays nums1 and nums2. Each element in nums1 and nums2 is an array of two integers: an id and a value. The arrays are sorted in ascending order by the id. Your task is to merge the two arrays into a single array, sorted by id. Each id should appear only once, and if an id appears in both arrays, its value should be the sum of the values from both arrays. If an id is present in only one array, its value remains as it is.

Leetcode 2576: Find the Maximum Number of Marked Indices

You are given a 0-indexed integer array nums. Initially, all indices are unmarked. You are allowed to perform the following operation any number of times: Pick two different unmarked indices i and j such that 2 * nums[i] <= nums[j], then mark both indices i and j. Return the maximum possible number of marked indices after performing this operation multiple times.

Leetcode 2592: Maximize Greatness of an Array

You are given an integer array nums. You can permute (rearrange) the elements of nums into a new array perm. Define the greatness of nums as the number of indices 0 <= i < nums.length where perm[i] > nums[i]. Your task is to return the maximum possible greatness you can achieve after permuting nums.

Leetcode 2697: Lexicographically Smallest Palindrome

You are given a string s consisting of lowercase English letters. You can perform operations on this string where in each operation, you replace a character in s with another lowercase English letter. The goal is to make s a palindrome using the minimum number of operations possible. If there are multiple ways to achieve the same minimum number of operations, return the lexicographically smallest palindrome string.

Leetcode 2824: Count Pairs Whose Sum is Less than Target

You are given a 0-indexed integer array nums and an integer target. Return the number of distinct pairs (i, j) such that 0 <= i < j < n and nums[i] + nums[j] < target.