All Posts

Leetcode 2602: Minimum Operations to Make All Array Elements Equal

You are given an array nums consisting of positive integers. You are also given an array queries, and for each query, you need to determine the minimum number of operations required to make all elements of nums equal to the query value. The allowed operation is to either increase or decrease an element by 1.

Leetcode 2606: Find the Substring With Maximum Cost

You are given a string s, a string chars of distinct characters, and an integer array vals of the same length as chars. The value of each character is determined by either its position in the alphabet or a corresponding value in the vals array if it is present in chars. The cost of a substring is the sum of the values of each character in that substring. Your goal is to find the maximum cost of any substring of s.

Leetcode 2607: Make K-Subarray Sums Equal

You are given a circular integer array arr and an integer k. In this circular array, the first element follows after the last one, and the last element precedes the first one. Your task is to determine the minimum number of operations required to make the sum of every subarray of length k equal. In each operation, you can pick any element in the array and either increase or decrease it by 1.

Leetcode 2610: Convert an Array Into a 2D Array With Conditions

Given an integer array, your task is to create a 2D array from the input array satisfying the following conditions:

  1. The 2D array should contain all the elements of the input array.
  2. Each row of the 2D array should contain distinct integers.
  3. The number of rows in the 2D array should be minimal. Return the resulting array. If there are multiple valid answers, return any of them.

Leetcode 2611: Mice and Cheese

You have two mice and a set of n different types of cheese. Each type of cheese has a different point value when eaten by either mouse. The first mouse must eat exactly k types of cheese, while the second mouse eats the remaining cheese types. Your task is to maximize the total points the two mice can achieve by distributing the cheese types between the mice.

Leetcode 2615: Sum of Distances

You are given a 0-indexed integer array nums. For each element nums[i], compute the sum of absolute differences |i - j| for all indices j where nums[j] == nums[i] and j != i. If there are no such indices, set the corresponding value in the result array to 0. Return the resulting array.