Hashing Redistribute Characters to Make All Strings Equal Solution In C++/Java/Python/JS Problem Description You are given an array of strings words (0-indexed). In one operation, pick two distinct indices i and j, where words[i] is a non-empty string, and move any character from words[i] to any position in words[j]. Return true if you can make every string in
Hashing Count Pairs That Form a Complete Day II Solution In C++/Java/Python/JS Problem Description Given an integer array hours representing times in hours, return an integer denoting the number of pairs i, j where i < j and hours[i] + hours[j] forms a complete day. A complete day is defined as a time duration that is an exact multiple of 24
Number of Submatrices That Sum to Target Solution In C++/Java/Python/JS Problem Description Given a matrix and a target, return the number of non-empty submatrices that sum to target. What is a Submatrix? A submatrix x1, y1, x2, y2 is the set of all cells matrix[x][y] with x1 <= x <= x2 and y1 <= y <= y2. Two
Hashing Count the Number of Beautiful Subarrays Solution In C++/Java/Python/JS Problem Description You are given a 0-indexed integer array nums. In one operation, you can: Choose two different indices i and j such that 0 <= i, j < nums.length. Choose a non-negative integer k such that the kth bit (0-indexed) in the binary representation of nums[i] and
Number of Wonderful Substrings Solution In C++/Java/Python/JS Problem Description A wonderful string is a string where at most one letter appears an odd number of times. For example, "ccjjc" and "abab" are wonderful, but "ab" is not. Given a string word that consists of the first ten lowercase English letters ('
Hashing Binary Subarrays With Sum Solutions in C++/Java/Python/JS Problem Description We are given a binary array nums containing only 0s and 1s) and an integer goal. The task is to return the number of non-empty contiguous subarrays whose elements sum up exactly to goal. What is a Subarray? A subarray is a contiguous part of the array, meaning
Hashing Sum of Digit Differences of All Pairs Solution In C++/Java/Python/JS Problem Description Given an array nums consisting of positive integers where all integers have the same number of digits. The digit difference between two integers is the count of different digits that are in the same position in the two integers. Return the sum of the digit differences between all
Query Kth Smallest Trimmed Number Solution In C++/Python/Java/JS Problem Description You are given a 0-indexed array of strings nums, where each string is of equal length and consists of only digits. You are also given a 0-indexed 2D integer array queries where queries[i] = [ki, trimi]. For each queries[i], you need to: Trim each number in nums
Find K Closest Elements Solution In C++/Python/Java/JS Problem Description Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array. The result should also be sorted in ascending order. An integer a is closer to x than an integer b if: |a - x| < |b -
Top K Frequent Words Solution In C++/Python/Java/JS Problem Description Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order. Examples: Input: words = ["i","love","
K-th Smallest Prime Fraction Solution In C++/Python/Java/JS Problem Description You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique. You are also given an integer k. For every i and j where 0 <= i < j < arr.length, we consider the fraction arr[i]
Find Subsequence of Length K With the Largest Sum Solution In C++/Python/Java/JS Problem Description You are given an integer array nums and an integer k. You want to find a subsequence of nums of length k that has the largest sum. Return any such subsequence as an integer array of length k. A subsequence is an array that can be derived from
Kth Largest Element in a Stream Solution In C++/Python/Java/JS Problem Description You are part of a university admissions office and need to keep track of the kth highest test score from applicants in real-time. This helps to determine cut-off marks for interviews and admissions dynamically as new applicants submit their scores. You are tasked to implement a class which,
Kth Largest Element in an Array Solution In C++/Python/Java/JS Problem Description Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting? Example Input: nums = [3,2,1,5,6,
The K Weakest Rows in a Matrix Solution In C++/Python/Java/JS Problem Description You are given an m x n binary matrix mat of 1's (representing soldiers) and 0's (representing civilians). The soldiers are positioned in front of the civilians. That is, all the 1's will appear to the left of all the 0'
Heaps Top K Frequent Elements Solution In C++/Python/Java/JS Problem Description Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Examples: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Explanation: Frequency of 1 is 3 and frequency of 2 is
Heaps Maximum Subsequence Score Solution In C++/Python/Java/JS Problem Description You are given two 0-indexed integer arrays nums1 and nums2 of equal length n and a positive integer k. You must choose a subsequence of indices from nums1 of length k. For chosen indices i0, i1, ..., ik - 1, your score is defined as: The sum of the
Heaps Maximum Elegance of a K-Length Subsequence Solution In C++/Python/Java/JS Problem Description You are given a 0-indexed 2D integer array items of length n and an integer k. items[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively. Let's define the elegance of a subsequence of items as total_profit
Heaps Maximum Performance of a Team Solution In C++/Python/Java/JS Problem Description You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith engineer respectively. Choose at most k different
Minimum Operations to Exceed Threshold Value II Solution In C++/Java/Python/Javascript Problem Description You are given a 0-indexed integer array nums, and an integer k. You are allowed to perform some operations on nums, where in a single operation, you can: Select the two smallest integers x and y from nums. Remove x and y from nums. Insert (min(x, y)
Maximum Number of Events That Can Be Attended Solution In C++/Java/Python/Javascript Problem Description You are given an array of events where events[i] = [startDay i, endDay i]. Every event i starts at startDay i and ends at endDay i. You can attend an event i at any day d where startTime i <= d <= endTime i. You can only attend
Maximum Number of Eaten Apples Problem Solution In C++/Java/Python/Javascript Problem Description There is a special kind of apple tree that grows apples every day for n days. On the ith day, the tree grows apples[i] apples that will rot after days[i] days, meaning they become rotten on day i + days[i] and can no longer be eaten.
Process Tasks Using Servers Solution In C++/Java/Python/Javascript Problem Description You are given two 0-indexed integer arrays servers and tasks of lengths n and m respectively. servers[i] is the weight of the i th server, and tasks[j] is the time needed to process the j th task in seconds. Tasks are assigned to the servers using
Most Frequent IDs Problem Solution In C++/Java/Python/Javascript Problem Description The problem involves tracking the frequency of IDs in a collection that changes over time. You have two integer arrays, nums and freq, of equal length n. Each element in nums represents an ID, and the corresponding element in freq indicates how many times that ID should be
Total Cost to Hire K Workers Problem Solution In C++/Java/Python/Javascript Problem Description You are given a 0-indexed integer array costs where costs[i] is the cost of hiring the ith worker. You are also given two integers k and candidates. We want to hire exactly k workers according to the following rules: You will run k sessions and hire exactly