Prefix Sum Problems
Master prefix sum problems with AI-powered solutions. Get instant coding assistance during your technical interviews for all 125 problems in this category.
Total Problems: 125
Easy: 15
Medium: 82
Hard: 28
Showing 50 of 125 problems
Problems
Scroll within this area to browse all problems
#
Title
Difficulty
Prefix Sum LeetCode Problems List
- 560. Subarray Sum Equals K - Medium - Prefix SumGiven an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k. A subarray is a contiguous non-empty seq... Topics: Array, Hash Table, Prefix Sum
- 238. Product of Array Except Self - Medium - Prefix SumGiven an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The produc... Topics: Array, Prefix Sum
- 1046. Max Consecutive Ones III - Medium - Prefix SumGiven a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.... Topics: Array, Binary Search, Sliding Window, Prefix Sum
- 912. Random Pick with Weight - Medium - Prefix SumYou are given a 0-indexed array of positive integers w where w[i] describes the weight of the ith index. You need to implement the function pickIndex(... Topics: Array, Math, Binary Search, Prefix Sum, Randomized
- 209. Minimum Size Subarray Sum - Medium - Prefix SumGiven an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to ... Topics: Array, Binary Search, Sliding Window, Prefix Sum
- 523. Continuous Subarray Sum - Medium - Prefix SumGiven an integer array nums and an integer k, return true if nums has a good subarray or false otherwise. A good subarray is a subarray where: its len... Topics: Array, Hash Table, Math, Prefix Sum
- 525. Contiguous Array - Medium - Prefix SumGiven a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.... Topics: Array, Hash Table, Prefix Sum
- 724. Find Pivot Index - Easy - Prefix SumGiven an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to th... Topics: Array, Prefix Sum
- 410. Split Array Largest Sum - Hard - Prefix SumGiven an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized. Return the... Topics: Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum
- 1966. Frequency of the Most Frequent Element - Medium - Prefix SumThe frequency of an element is the number of times it occurs in an array. You are given an integer array nums and an integer k. In one operation, you ... Topics: Array, Binary Search, Greedy, Sliding Window, Sorting, Prefix Sum
- 2001. Jump Game VII - Medium - Prefix SumYou are given a 0-indexed binary string s and two integers minJump and maxJump. In the beginning, you are standing at index 0, which is equal to '0'. ... Topics: String, Dynamic Programming, Sliding Window, Prefix Sum
- 3265. Maximum Good Subarray Sum - Medium - Prefix SumYou are given an array nums of length n and a positive integer k. A subarray of nums is called good if the absolute difference between its first and l... Topics: Array, Hash Table, Prefix Sum
- 1603. Running Sum of 1d Array - Easy - Prefix SumGiven an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums.... Topics: Array, Prefix Sum
- 1538. Maximum Points You Can Obtain from Cards - Medium - Prefix SumThere are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints. In ... Topics: Array, Sliding Window, Prefix Sum
- 1184. Car Pooling - Medium - Prefix SumThere is a car with capacity empty seats. The vehicle only drives east (i.e., it cannot turn around and drive west). You are given the integer capacit... Topics: Array, Sorting, Heap (Priority Queue), Simulation, Prefix Sum
- 966. Binary Subarrays With Sum - Medium - Prefix SumGiven a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal. A subarray is a contiguous part of the array.... Topics: Array, Hash Table, Sliding Window, Prefix Sum
- 1206. Corporate Flight Bookings - Medium - Prefix SumThere are n flights that are labeled from 1 to n. You are given an array of flight bookings bookings, where bookings[i] = [firsti, lasti, seatsi] repr... Topics: Array, Prefix Sum
- 2721. Sum of Distances - Medium - Prefix SumYou are given a 0-indexed integer array nums. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that... Topics: Array, Hash Table, Prefix Sum
- 1016. Subarray Sums Divisible by K - Medium - Prefix SumGiven an integer array nums and an integer k, return the number of non-empty subarrays that have a sum divisible by k. A subarray is a contiguous part... Topics: Array, Hash Table, Prefix Sum
- 2488. Divide Intervals Into Minimum Number of Groups - Medium - Prefix SumYou are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti]. You have to divide ... Topics: Array, Two Pointers, Greedy, Sorting, Heap (Priority Queue), Prefix Sum
- 1240. Stone Game II - Medium - Prefix SumAlice and Bob continue their games with piles of stones. There are a number of piles arranged in a row, and each pile has a positive integer number of... Topics: Array, Math, Dynamic Programming, Prefix Sum, Game Theory
- 3639. Zero Array Transformation I - Medium - Prefix SumYou are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri]. For each queries[i]: Select a subset of indices w... Topics: Array, Prefix Sum
- 892. Shortest Subarray with Sum at Least K - Hard - Prefix SumGiven 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. If there is no su... Topics: Array, Binary Search, Queue, Sliding Window, Heap (Priority Queue), Prefix Sum, Monotonic Queue
- 713. Subarray Product Less Than K - Medium - Prefix SumGiven an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is s... Topics: Array, Binary Search, Sliding Window, Prefix Sum
- 2165. Plates Between Candles - Medium - Prefix SumThere is a long table with a line of plates and candles arranged on top of it. You are given a 0-indexed string s consisting of characters '*' and '|'... Topics: Array, String, Binary Search, Prefix Sum
- 2449. Maximum Number of Robots Within Budget - Hard - Prefix SumYou have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] unit... Topics: Array, Binary Search, Queue, Sliding Window, Heap (Priority Queue), Prefix Sum, Monotonic Queue
- 1776. Minimum Operations to Reduce X to Zero - Medium - Prefix SumYou are given an integer array nums and an integer x. In one operation, you can either remove the leftmost or the rightmost element from the array num... Topics: Array, Hash Table, Binary Search, Sliding Window, Prefix Sum
- 303. Range Sum Query - Immutable - Easy - Prefix SumGiven an integer array nums, handle multiple queries of the following type: Calculate the sum of the elements of nums between indices left and right i... Topics: Array, Design, Prefix Sum
- 1859. Change Minimum Characters to Satisfy One of Three Conditions - Medium - Prefix SumYou are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter.... Topics: Hash Table, String, Counting, Prefix Sum
- 878. Shifting Letters - Medium - Prefix SumYou are given a string s of lowercase English letters and an integer array shifts of the same length. Call the shift() of a letter, the next letter in... Topics: Array, String, Prefix Sum
- 1370. Count Number of Nice Subarrays - Medium - Prefix SumGiven an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub... Topics: Array, Hash Table, Math, Sliding Window, Prefix Sum
- 1833. Find the Highest Altitude - Easy - Prefix SumThere is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitu... Topics: Array, Prefix Sum
- 3031. Construct Product Matrix - Medium - Prefix SumGiven a 0-indexed 2D integer matrix grid of size n * m, we define a 0-indexed 2D matrix p of size n * m as the product matrix of grid if the following... Topics: Array, Matrix, Prefix Sum
- 1393. Maximum Value of K Coins From Piles - Hard - Prefix SumThere are n piles of coins on a table. Each pile consists of a positive number of coins of assorted denominations. In one move, you can choose any coi... Topics: Array, Dynamic Programming, Prefix Sum
- 3653. Maximum Subarray Sum With Length Divisible by K - Medium - Prefix SumYou are given an array of integers nums and an integer k. Return the maximum sum of a subarray of nums, such that the size of the subarray is divisibl... Topics: Array, Hash Table, Prefix Sum
- 3644. Minimum Positive Sum Subarray - Easy - Prefix SumYou are given an integer array nums and two integers l and r. Your task is to find the minimum sum of a subarray whose size is between l and r (inclus... Topics: Array, Sliding Window, Prefix Sum
- 2368. Sum of Total Strength of Wizards - Hard - Prefix SumAs the ruler of a kingdom, you have an army of wizards at your command. You are given a 0-indexed integer array strength, where strength[i] denotes th... Topics: Array, Stack, Monotonic Stack, Prefix Sum
- 1872. Can You Eat Your Favorite Candy on Your Favorite Day? - Medium - Prefix SumYou are given a (0-indexed) array of positive integers candiesCount where candiesCount[i] represents the number of candies of the ith type you have. Y... Topics: Array, Prefix Sum
- 1985. Maximum Subarray Min-Product - Medium - Prefix SumThe min-product of an array is equal to the minimum value in the array multiplied by the array's sum. For example, the array [3,2,5] (minimum value is... Topics: Array, Stack, Monotonic Stack, Prefix Sum
- 732. My Calendar III - Hard - Prefix SumA k-booking happens when k events have some non-empty intersection (i.e., there is some time that is common to all k events.) You are given some event... Topics: Binary Search, Design, Segment Tree, Prefix Sum, Ordered Set
- 1555. Number of Ways of Cutting a Pizza - Hard - Prefix SumGiven a rectangular pizza represented as a rows x cols matrix containing the following characters: 'A' (an apple) and '.' (empty cell) and given the i... Topics: Array, Dynamic Programming, Memoization, Matrix, Prefix Sum
- 2334. Number of Flowers in Full Bloom - Hard - Prefix SumYou are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the ith flower will be in full bloom from starti to endi (... Topics: Array, Hash Table, Binary Search, Sorting, Prefix Sum, Ordered Set
- 1631. Number of Sub-arrays With Odd Sum - Medium - Prefix SumGiven an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 109 + 7.... Topics: Array, Math, Dynamic Programming, Prefix Sum
- 2145. Grid Game - Medium - Prefix SumYou are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots a... Topics: Array, Matrix, Prefix Sum
- 2044. Number of Wonderful Substrings - Medium - Prefix SumA 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... Topics: Hash Table, String, Bit Manipulation, Prefix Sum
- 3948. Maximum Number of Subsequences After One Inserting - Medium - Prefix SumYou are given a string s consisting of uppercase English letters. You are allowed to insert at most one uppercase English letter at any position (incl... Topics: String, Dynamic Programming, Greedy, Prefix Sum
- 1042. Minimum Cost to Merge Stones - Hard - Prefix SumThere are n piles of stones arranged in a row. The ith pile has stones[i] stones. A move consists of merging exactly k consecutive piles into one pile... Topics: Array, Dynamic Programming, Prefix Sum
- 3913. Partition Array to Minimize XOR - Medium - Prefix SumYou are given an integer array nums and an integer k. Your task is to partition nums into k non-empty subarrays. For each subarray, compute the bitwis... Topics: Array, Dynamic Programming, Bit Manipulation, Prefix Sum
- 1145. Number of Submatrices That Sum to Target - Hard - Prefix SumGiven a matrix and a target, return the number of non-empty submatrices that sum to target. A submatrix x1, y1, x2, y2 is the set of all cells matrix[... Topics: Array, Hash Table, Matrix, Prefix Sum
- 2134. Maximize the Confusion of an Exam - Medium - Prefix SumA teacher is writing a test with n true/false questions, with 'T' denoting true and 'F' denoting false. He wants to confuse the students by maximizing... Topics: String, Binary Search, Sliding Window, Prefix Sum
- 1311. Largest Magic Square - Medium - Prefix SumA k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integer... Topics: Array, Matrix, Prefix Sum
- 2018. Minimum Space Wasted From Packaging - Hard - Prefix SumYou have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (... Topics: Array, Binary Search, Sorting, Prefix Sum
- 3794. Find the Minimum Amount of Time to Brew Potions - Medium - Prefix SumYou are given two integer arrays, skill and mana, of length n and m, respectively. In a laboratory, n wizards must brew m potions in order. Each potio... Topics: Array, Simulation, Prefix Sum
- 2465. Shifting Letters II - Medium - Prefix SumYou are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift t... Topics: Array, String, Prefix Sum
- 3262. Find Polygon With the Largest Perimeter - Medium - Prefix SumYou are given an array of positive integers nums of length n. A polygon is a closed plane figure that has at least 3 sides. The longest side of a poly... Topics: Array, Greedy, Sorting, Prefix Sum
- 2309. Maximize Number of Subsequences in a String - Medium - Prefix SumYou are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters. You c... Topics: String, Greedy, Prefix Sum
- 1990. Get Biggest Three Rhombus Sums in a Grid - Medium - Prefix SumYou are given an m x n integer matrix grid. A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid. Th... Topics: Array, Math, Sorting, Heap (Priority Queue), Matrix, Prefix Sum
- 2205. Find Good Days to Rob the Bank - Medium - Prefix SumYou and a gang of thieves are planning on robbing a bank. You are given a 0-indexed integer array security, where security[i] is the number of guards ... Topics: Array, Dynamic Programming, Prefix Sum
- 3850. Equal Sum Grid Partition II - Hard - Prefix SumYou are given an m x n matrix grid of positive integers. Your task is to determine if it is possible to make either one horizontal or one vertical cut... Topics: Array, Hash Table, Matrix, Enumeration, Prefix Sum
- 304. Range Sum Query 2D - Immutable - Medium - Prefix SumGiven a 2D matrix matrix, handle multiple queries of the following type: Calculate the sum of the elements of matrix inside the rectangle defined by i... Topics: Array, Design, Matrix, Prefix Sum
- 1473. Find the Longest Substring Containing Vowels in Even Counts - Medium - Prefix SumGiven the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must ... Topics: Hash Table, String, Bit Manipulation, Prefix Sum
- 3647. Zero Array Transformation III - Medium - Prefix SumYou are given an integer array nums of length n and a 2D array queries where queries[i] = [li, ri]. Each queries[i] represents the following action on... Topics: Array, Greedy, Sorting, Heap (Priority Queue), Prefix Sum
- 1242. Matrix Block Sum - Medium - Prefix SumGiven a m x n matrix mat and an integer k, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for: i - k <= r <= i + ... Topics: Array, Matrix, Prefix Sum
- 2576. Minimum Penalty for a Shop - Medium - Prefix SumYou are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y': if the ith chara... Topics: String, Prefix Sum
- 3310. Count the Number of Houses at a Certain Distance II - Hard - Prefix SumYou are given three positive integers n, x, and y. In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting ... Topics: Graph, Prefix Sum
- 1983. Maximum Population Year - Easy - Prefix SumYou are given a 2D integer array logs where each logs[i] = [birthi, deathi] indicates the birth and death years of the ith person. The population of s... Topics: Array, Counting, Prefix Sum
- 2229. Maximum Fruits Harvested After at Most K Steps - Hard - Prefix SumFruits are available at some positions on an infinite x-axis. You are given a 2D integer array fruits where fruits[i] = [positioni, amounti] depicts a... Topics: Array, Binary Search, Sliding Window, Prefix Sum
- 3271. Count the Number of Houses at a Certain Distance I - Medium - Prefix SumYou are given three positive integers n, x, and y. In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting ... Topics: Breadth-First Search, Graph, Prefix Sum
- 1435. XOR Queries of a Subarray - Medium - Prefix SumYou are given an array arr of positive integers. You are also given the array queries where queries[i] = [lefti, righti]. For each query i compute the... Topics: Array, Bit Manipulation, Prefix Sum
- 3406. Find All Possible Stable Binary Arrays I - Medium - Prefix SumYou are given 3 positive integers zero, one, and limit. A binary array arr is called stable if: The number of occurrences of 0 in arr is exactly zero.... Topics: Dynamic Programming, Prefix Sum
- 2002. Stone Game VIII - Hard - Prefix SumAlice and Bob take turns playing a game, with Alice starting first. There are n stones arranged in a row. On each player's turn, while the number of s... Topics: Array, Math, Dynamic Programming, Prefix Sum, Game Theory
- 3835. Count Partitions With Max-Min Difference at Most K - Medium - Prefix SumYou are given an integer array nums and an integer k. Your task is to partition nums into one or more non-empty contiguous segments such that in each ... Topics: Array, Dynamic Programming, Queue, Sliding Window, Prefix Sum, Monotonic Queue
- 2625. Increment Submatrices by One - Medium - Prefix SumYou are given a positive integer n, indicating that we initially have an n x n 0-indexed integer matrix mat filled with zeroes. You are also given a 2... Topics: Array, Matrix, Prefix Sum
- 2504. Find All Good Indices - Medium - Prefix SumYou are given a 0-indexed integer array nums of size n and a positive integer k. We call an index i in the range k <= i < n - k good if the following ... Topics: Array, Dynamic Programming, Prefix Sum
- 1783. Ways to Make a Fair Array - Medium - Prefix SumYou are given an integer array nums. You can choose exactly one index (0-indexed) and remove the element. Notice that the index of the elements may ch... Topics: Array, Prefix Sum
- 1553. Count Triplets That Can Form Two Arrays of Equal XOR - Medium - Prefix SumGiven an array of integers arr. We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). Let's define a and b as follows: a = ... Topics: Array, Hash Table, Math, Bit Manipulation, Prefix Sum
- 2342. Minimum Average Difference - Medium - Prefix SumYou are given a 0-indexed integer array nums of length n. The average difference of the index i is the absolute difference between the average of the ... Topics: Array, Prefix Sum
- 3622. Maximum Frequency of an Element After Performing Operations I - Medium - Prefix SumYou are given an integer array nums and two integers k and numOperations. You must perform an operation numOperations times on nums, where in each ope... Topics: Array, Binary Search, Sliding Window, Sorting, Prefix Sum
- 3761. Maximum Difference Between Even and Odd Frequency II - Hard - Prefix SumYou are given a string s and an integer k. Your task is to find the maximum difference between the frequency of two characters, freq[a] - freq[b], in ... Topics: String, Sliding Window, Enumeration, Prefix Sum
- 2394. Count Subarrays With Score Less Than K - Hard - Prefix SumThe score of an array is defined as the product of its sum and its length. For example, the score of [1, 2, 3, 4, 5] is (1 + 2 + 3 + 4 + 5) * 5 = 75. ... Topics: Array, Binary Search, Sliding Window, Prefix Sum
- 3034. Points That Intersect With Cars - Easy - Prefix SumYou are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti,... Topics: Array, Hash Table, Prefix Sum
- 2571. Find the Pivot Integer - Easy - Prefix SumGiven a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements bet... Topics: Math, Prefix Sum
- 3618. Find the Original Typed String II - Hard - Prefix SumAlice is attempting to type a specific string on her computer. However, she tends to be clumsy and may press a key for too long, resulting in a charac... Topics: String, Dynamic Programming, Prefix Sum
- 3141. Minimum Size Subarray in Infinite Array - Medium - Prefix SumYou are given a 0-indexed array nums and an integer target. A 0-indexed array infinite_nums is generated by infinitely appending the elements of nums ... Topics: Array, Hash Table, Sliding Window, Prefix Sum
- 3311. Ant on the Boundary - Easy - Prefix SumAn ant is on a boundary. It sometimes goes left and sometimes right. You are given an array of non-zero integers nums. The ant starts reading nums fro... Topics: Array, Simulation, Prefix Sum
- 1831. Ways to Split Array Into Three Subarrays - Medium - Prefix SumA split of an integer array is good if: The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left t... Topics: Array, Two Pointers, Binary Search, Prefix Sum
- 3535. Find the Count of Monotonic Pairs I - Hard - Prefix SumYou are given an array of positive integers nums of length n. We call a pair of non-negative integer arrays (arr1, arr2) monotonic if: The lengths of ... Topics: Array, Math, Dynamic Programming, Combinatorics, Prefix Sum
- 2290. Removing Minimum Number of Magic Beans - Medium - Prefix SumYou are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag. Remove any... Topics: Array, Greedy, Sorting, Enumeration, Prefix Sum
- 3687. Longest Special Path - Hard - Prefix SumYou are given an undirected tree rooted at node 0 with n nodes numbered from 0 to n - 1, represented by a 2D array edges of length n - 1, where edges[... Topics: Array, Hash Table, Tree, Depth-First Search, Prefix Sum
- 1321. Get Equal Substrings Within Budget - Medium - Prefix SumYou are given two strings s and t of the same length and an integer maxCost. You want to change s to t. Changing the ith character of s to ith charact... Topics: String, Binary Search, Sliding Window, Prefix Sum
- 2469. Longest Subsequence With Limited Sum - Easy - Prefix SumYou are given an integer array nums of length n, and an integer array queries of length m. Return an array answer of length m where answer[i] is the m... Topics: Array, Binary Search, Greedy, Sorting, Prefix Sum
- 1693. Sum of All Odd Length Subarrays - Easy - Prefix SumGiven an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the arr... Topics: Array, Math, Prefix Sum
- 2330. Maximum Total Beauty of the Gardens - Hard - Prefix SumAlice is a caretaker of n gardens and she wants to plant flowers to maximize the total beauty of all her gardens. You are given a 0-indexed integer ar... Topics: Array, Two Pointers, Binary Search, Greedy, Sorting, Enumeration, Prefix Sum
- 2878. Apply Operations to Make All Array Elements Equal to Zero - Medium - Prefix SumYou are given a 0-indexed integer array nums and a positive integer k. You can apply the following operation on the array any number of times: Choose ... Topics: Array, Prefix Sum
- 2325. Number of Ways to Select Buildings - Medium - Prefix SumYou are given a 0-indexed binary string s which represents the types of buildings along a street where: s[i] = '0' denotes that the ith building is an... Topics: String, Dynamic Programming, Prefix Sum
- 2006. Find the Student that Will Replace the Chalk - Medium - Prefix SumThere are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the st... Topics: Array, Binary Search, Simulation, Prefix Sum
- 2102. Find the Middle Index in Array - Easy - Prefix SumGiven a 0-indexed integer array nums, find the leftmost middleIndex (i.e., the smallest amongst all the possible ones). A middleIndex is an index wher... Topics: Array, Prefix Sum
- 2714. Left and Right Sum Differences - Easy - Prefix SumYou are given a 0-indexed integer array nums of size n. Define two arrays leftSum and rightSum where: leftSum[i] is the sum of elements to the left of... Topics: Array, Prefix Sum
- 914. Random Point in Non-overlapping Rectangles - Medium - Prefix SumYou are given an array of non-overlapping axis-aligned rectangles rects where rects[i] = [ai, bi, xi, yi] indicates that (ai, bi) is the bottom-left c... Topics: Array, Math, Binary Search, Reservoir Sampling, Prefix Sum, Ordered Set, Randomized
- 2471. Minimum Amount of Time to Collect Garbage - Medium - Prefix SumYou are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of... Topics: Array, String, Prefix Sum
- 2530. Minimize Maximum of Array - Medium - Prefix SumYou are given a 0-indexed array nums comprising of n non-negative integers. In one operation, you must: Choose an integer i such that 1 <= i < n and n... Topics: Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum
- 1787. Sum of Absolute Differences in a Sorted Array - Medium - Prefix SumYou are given an integer array nums sorted in non-decreasing order. Build and return an integer array result with the same length as nums such that re... Topics: Array, Math, Prefix Sum
- 2787. Movement of Robots - Medium - Prefix SumSome robots are standing on an infinite number line with their initial coordinates given by a 0-indexed integer array nums and will start moving once ... Topics: Array, Brainteaser, Sorting, Prefix Sum
- 2059. Unique Length-3 Palindromic Subsequences - Medium - Prefix SumGiven a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to ob... Topics: Hash Table, String, Bit Manipulation, Prefix Sum
- 2529. Range Product Queries of Powers - Medium - Prefix SumGiven a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is so... Topics: Array, Bit Manipulation, Prefix Sum
- 3643. Zero Array Transformation II - Medium - Prefix SumYou are given an integer array nums of length n and a 2D array queries where queries[i] = [li, ri, vali]. Each queries[i] represents the following act... Topics: Array, Binary Search, Prefix Sum
- 3955. Threshold Majority Queries - Hard - Prefix SumYou are given an integer array nums of length n and an array queries, where queries[i] = [li, ri, thresholdi]. Return an array of integers ans where a... Topics: Array, Hash Table, Binary Search, Divide and Conquer, Counting, Prefix Sum
- 2538. Minimum Cost to Make Array Equal - Hard - Prefix SumYou are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: Incre... Topics: Array, Binary Search, Greedy, Sorting, Prefix Sum
- 2358. Number of Ways to Split Array - Medium - Prefix SumYou are given a 0-indexed integer array nums of length n. nums contains a valid split at index i if the following are true: The sum of the first i + 1... Topics: Array, Prefix Sum
- 2055. Describe the Painting - Medium - Prefix SumThere is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each seg... Topics: Array, Hash Table, Sorting, Prefix Sum
- 1649. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target - Medium - Prefix SumGiven an array nums and an integer target, return the maximum number of non-empty non-overlapping subarrays such that the sum of values in each subarr... Topics: Array, Hash Table, Greedy, Prefix Sum
- 3470. Maximum Score From Grid Operations - Hard - Prefix SumYou are given a 2D matrix grid of size n x n. Initially, all cells of the grid are colored white. In one operation, you can select any cell of indices... Topics: Array, Dynamic Programming, Matrix, Prefix Sum
- 2005. Check if All the Integers in a Range Are Covered - Easy - Prefix SumYou are given a 2D integer array ranges and two integers left and right. Each ranges[i] = [starti, endi] represents an inclusive interval between star... Topics: Array, Hash Table, Prefix Sum
- 1895. Minimum Number of Operations to Move All Balls to Each Box - Medium - Prefix SumYou have n boxes. You are given a binary string boxes of length n, where boxes[i] is '0' if the ith box is empty, and '1' if it contains one ball. In ... Topics: Array, String, Prefix Sum
- 731. My Calendar II - Medium - Prefix SumYou are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a triple booking. A triple booking h... Topics: Array, Binary Search, Design, Segment Tree, Prefix Sum, Ordered Set
- 363. Max Sum of Rectangle No Larger Than K - Hard - Prefix SumGiven an m x n matrix matrix and an integer k, return the max sum of a rectangle in the matrix such that its sum is no larger than k. It is guaranteed... Topics: Array, Binary Search, Matrix, Prefix Sum, Ordered Set
- 3789. Maximize Subarrays After Removing One Conflicting Pair - Hard - Prefix SumYou are given an integer n which represents an array nums containing the numbers from 1 to n in order. Additionally, you are given a 2D array conflict... Topics: Array, Segment Tree, Enumeration, Prefix Sum
- 1037. Minimum Number of K Consecutive Bit Flips - Hard - Prefix SumYou are given a binary array nums and an integer k. A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in t... Topics: Array, Bit Manipulation, Queue, Sliding Window, Prefix Sum
- 1514. Minimum Value to Get Positive Step by Step Sum - Easy - Prefix SumGiven an array of integers nums, you start with an initial positive value startValue. In each iteration, you calculate the step by step sum of startVa... Topics: Array, Prefix Sum
- 2508. Maximum Sum of an Hourglass - Medium - Prefix SumYou are given an m x n integer matrix grid. We define an hourglass as a part of the matrix with the following form: Return the maximum sum of the elem... Topics: Array, Matrix, Prefix Sum
- 2359. Maximum White Tiles Covered by a Carpet - Medium - Prefix SumYou are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white. You are als... Topics: Array, Binary Search, Greedy, Sliding Window, Sorting, Prefix Sum
- 2240. Intervals Between Identical Elements - Medium - Prefix SumYou are given a 0-indexed array of n integers arr. The interval between two elements in arr is defined as the absolute difference between their indice... Topics: Array, Hash Table, Prefix Sum
- 2691. Count Vowel Strings in Ranges - Medium - Prefix SumYou are given a 0-indexed array of strings words and a 2D array of integers queries. Each query queries[i] = [li, ri] asks us to find the number of st... Topics: Array, String, Prefix Sum
- 1413. Maximum Side Length of a Square with Sum Less than or Equal to Threshold - Medium - Prefix SumGiven a m x n matrix mat and an integer threshold, return the maximum side-length of a square with a sum less than or equal to threshold or return 0 i... Topics: Array, Binary Search, Matrix, Prefix Sum
- 689. Maximum Sum of 3 Non-Overlapping Subarrays - Hard - Prefix SumGiven an integer array nums and an integer k, find three non-overlapping subarrays of length k with maximum sum and return them. Return the result as ... Topics: Array, Dynamic Programming, Sliding Window, Prefix Sum
Related LeetCode Topics
- Array LeetCode Problems
- Backtracking LeetCode Problems
- Biconnected Component LeetCode Problems
- Binary Indexed Tree LeetCode Problems
- Binary Search LeetCode Problems
- Binary Search Tree LeetCode Problems
- Binary Tree LeetCode Problems
- Bit Manipulation LeetCode Problems
- Bitmask LeetCode Problems
- Brainteaser LeetCode Problems
- Breadth-First Search LeetCode Problems
- Bucket Sort LeetCode Problems
- Combinatorics LeetCode Problems
- Concurrency LeetCode Problems
- Counting LeetCode Problems
- Counting Sort LeetCode Problems
- Data Stream LeetCode Problems
- Database LeetCode Problems
- Depth-First Search LeetCode Problems
- Design LeetCode Problems