Monotonic Queue

Monotonic Queue

Twenty questions on the monotonic queue (deque) pattern, for sliding-window minimum and maximum problems.

Continuous Subarrays

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

Count Partitions With Max-Min Difference at Most K

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

Count Prime-Gap Balanced Subarrays

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

Jump Game VI

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

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...

Maximum Sum Circular Subarray

medium
Given a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.

Minimum Number of Coins for Fruits

medium
You are given an 0-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the (i + 1)th fruit.

Constrained Subsequence Sum

hard
Given an integer array nums and an integer k, return the maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence,...

Count Non-Decreasing Subarrays After K Operations

hard
You are given an array nums of n integers and an integer k.

Count Subarrays With Fixed Bounds

hard
You are given an integer array nums and two integers minK and maxK.

Delivering Boxes from Storage to Ports

hard
You have the task of delivering some boxes from storage to their ports using only one ship.

Find Maximum Non-decreasing Array Length

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

Longest Increasing Subsequence II

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

Max Value of Equation

hard
You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <=...

Maximum Number of Robots Within Budget

hard
You have n robots.

Maximum Number of Tasks You Can Assign

hard
You have n tasks and m workers.

Shortest Subarray with Sum at Least K

hard
Given an integer array nums and an integer k, return the length of the shortest non-empty subarray of nums with a sum of at least k.

Sliding Window Maximum

hard
You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right.