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:
- The 2D array should contain all the elements of the input array.
- Each row of the 2D array should contain distinct integers.
- 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.