Skip to content
Optimal Lab

Practice · 4 problems

Prefix Sum

0 of 4 solved on this device

Watch it first · interactivePrefix sums: range sums in O(1) →Read the explainer · optimal-roundWhen to use it, and its look-alikes ↗
  1. 156Find Pivot IndexGiven an array `nums`, return the leftmost index where the sum of everything strictly to its left equals the sum of everything strictly to its right. Return -1 if no such index exists.Easy
  2. 157Range Sum Query - ImmutableGiven an integer array `nums`, handle many queries asking for the sum of the elements between indices left and right inclusive. Implement the NumArray class with sumRange(left, right).Easy
  3. 158Range Sum Query 2D - ImmutableGiven a 2D matrix, handle queries for the sum of the rectangle defined by its upper left and lower right corners. Implement NumMatrix with sumRegion(row1, col1, row2, col2).Medium
  4. 159Continuous Subarray SumGiven an integer array `nums` and an integer `k`, return true if there is a contiguous subarray of length AT LEAST TWO whose sum is a multiple of k.Medium