Heap

Heap

Forty-five questions on heaps and priority queues, for efficiently tracking the smallest or largest elements in a stream.

Delete Greatest Value in Each Row

easy
You are given an m x n matrix grid consisting of positive integers.

Final Array State After K Multiplication Operations I

easy
You are given an integer array nums, an integer k, and an integer multiplier.

Find Subsequence of Length K With the Largest Sum

easy
You are given an integer array nums and an integer k.

Find X-Sum of All K-Long Subarrays I

easy
You are given an array nums of n integers and two integers k and x.

Largest Number After Digit Swaps by Parity

easy
You are given a positive integer num.

Last Stone Weight

easy
You are given an array of integers stones where stones[i] is the weight of the ith stone.

Make Array Zero by Subtracting Equal Amounts

easy
You are given a non-negative integer array nums.

Minimum Amount of Time to Fill Cups

easy
You have a water dispenser that can dispense cold, warm, and hot water.

Minimum Number Game

easy
You are given a 0-indexed integer array nums of even length and there is also an empty array arr.

Minimum Pair Removal to Sort Array I

easy
Given an array nums, you can perform the following operation any number of times: Return the minimum number of operations needed to make the array non-decreasing.

Relative Ranks

easy
You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition.

Take Gifts From the Richest Pile

easy
You are given an integer array gifts denoting the number of gifts in various piles.

Avoid Flood in The City

medium
Your country has an infinite number of lakes.

Car Pooling

medium
There is a car with capacity empty seats.

Cheapest Flights Within K Stops

medium
There are n cities connected by some number of flights.

Choose K Elements With Maximum Sum

medium
You are given two integer arrays, nums1 and nums2, both of length n, along with a positive integer k.

Construct String With Repeat Limit

medium
You are given a string s and an integer repeatLimit.

Continuous Subarrays

medium
You are given a 0-indexed integer array nums.

Diagonal Traverse II

medium
Given a 2D integer array nums, return all elements of nums in diagonal order as shown in the below images.

Digit Operations to Make Two Integers Equal

medium
You are given two integers n and m that consist of the same number of digits.

Distant Barcodes

medium
In a warehouse, there is a row of barcodes, where the ith barcode is barcodes[i].

Divide Intervals Into Minimum Number of Groups

medium
You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti].

Find a Safe Walk Through a Grid

medium
You are given an m x n binary matrix grid and an integer health.

Find K Closest Elements

medium
Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array.

Find K Pairs with Smallest Sums

medium
You are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k.

Find Kth Largest XOR Coordinate Value

medium
You are given a 2D matrix of size m x n, consisting of non-negative integers.

Find Minimum Time to Reach Last Room I

medium
There is a dungeon with n x m rooms arranged as a grid.

Find Minimum Time to Reach Last Room II

medium
There is a dungeon with n x m rooms arranged as a grid.

Find Score of an Array After Marking All Elements

medium
You are given an array nums consisting of positive integers.

Find the Kth Largest Integer in the Array

medium
You are given an array of strings nums and an integer k.

Find the Safest Path in a Grid

medium
You are given a 0-indexed 2D matrix grid of size n x n, where (r, c) represents: You are initially positioned at cell (0, 0).

Furthest Building You Can Reach

medium
You are given an integer array heights representing the heights of buildings, some bricks, and some ladders.

Get Biggest Three Rhombus Sums in a Grid

medium
You are given an m x n integer matrix grid​​​.

Jump Game VI

medium
You are given a 0-indexed integer array nums and an integer k.

K Closest Points to Origin

medium
Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0).

K Highest Ranked Items Within a Price Range

medium
You are given a 0-indexed 2D integer array grid of size m x n that represents a map of the items in a shop.

K-th Nearest Obstacle Queries

medium
There is an infinite 2D plane.

K-th Smallest Prime Fraction

medium
You are given a sorted integer array arr containing 1 and prime numbers, where all the integers of arr are unique.

Kth Largest Element in an Array

medium
Given an integer array nums and an integer k, return the kth largest element in the array.

Kth Smallest Element in a Sorted Matrix

medium
Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.

Lexicographically Minimum String After Removing Stars

medium
You are given a string s.

Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

medium
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray...

Longest Happy String

medium
A string s is called happy if it satisfies the following conditions: Given three integers a, b, and c, return the longest possible happy string.

Mark Elements on Array by Performing Queries

medium
You are given a 0-indexed array nums of size n consisting of positive integers.

Max Sum of a Pair With Equal Sum of Digits

medium
You are given a 0-indexed array nums consisting of positive integers.