Arrays

Ordered indexable collection for O(1) access by position.

Arrays Practice Problems

Easy

20 problems
  1. 274

    Two Sum

    Find the two numbers in an array that add up to a target value.

    easy
  2. 275

    Remove Element

    Remove every occurrence of a value from an array in place.

    easy
  3. 276

    Plus One

    Add one to a large number represented as an array of digits.

    easy
  4. 277

    Pascal's Triangle

    Build the first few rows of Pascal's triangle.

    easy
  5. 278

    Majority Element

    Find the value that appears in more than half the array.

    easy
  6. 279

    Find All Numbers Disappeared in an Array

    Find every number missing from a 1..n ranged array, in place.

    easy
  7. 280

    Third Maximum Number

    Find the third distinct largest number in an array.

    easy
  8. 281

    Array Partition

    Pair up array values to maximize the sum of each pair’s minimum.

    easy
  9. 282

    Check If N and Its Double Exist

    Check whether one array value is exactly double another.

    easy
  10. 283

    Replace Elements with Greatest Element on Right Side

    Replace each value with the greatest value to its right.

    easy
  11. 284

    Duplicate Zeros

    Duplicate every zero in place, shifting later values right.

    easy
  12. 285

    Shuffle the Array

    Interleave two halves of an array back into one sequence.

    easy
  13. 286

    Build Array from Permutation

    Build a new array where each value is looked up through itself.

    easy
  14. 287

    Concatenation of Array

    Concatenate an array with itself into one longer array.

    easy
  15. 288

    Richest Customer Wealth

    Find the customer with the most total money across accounts.

    easy
  16. 289

    Kids With the Greatest Number of Candies

    Check which kids could have the most candies after a bonus.

    easy
  17. 290

    Monotonic Array

    Check whether an array is entirely non-increasing or non-decreasing.

    easy
  18. 291

    Find Numbers with Even Number of Digits

    Count how many numbers in an array have an even digit count.

    easy
  19. 292

    Maximum Product of Two Elements in an Array

    Maximize (a-1) * (b-1) over two distinct array elements.

    easy
  20. 293

    Transpose Matrix

    Flip a matrix over its main diagonal.

    easy

Medium

14 problems
  1. 294

    Pivot Array

    Partition an array around a pivot value while keeping relative order.

    medium
  2. 295

    Spiral Matrix

    Return every element of a matrix in spiral order.

    medium
  3. 296

    Rotate Image

    Rotate a square matrix 90 degrees in place.

    medium
  4. 297

    Set Matrix Zeroes

    Zero out the row and column of every zero in a matrix, in place.

    medium
  5. 298

    Game of Life

    Advance a grid of cells one generation under Conway’s rules, in place.

    medium
  6. 299

    Next Greater Element II

    Find the next greater value for each element in a circular array.

    medium
  7. 300

    Daily Temperatures

    Find how many days until a warmer temperature, for each day.

    medium
  8. 301

    Majority Element II

    Find every value that appears more than n/3 times in an array.

    medium
  9. 302

    Find the Duplicate Number

    Find the one repeated number without modifying the array.

    medium
  10. 303

    Non-decreasing Array

    Check if an array can become non-decreasing by changing one element.

    medium
  11. 304

    Array Nesting

    Find the longest cycle formed by repeatedly indexing into a permutation.

    medium
  12. 305

    4Sum II

    Count quadruples across four arrays whose sums add up to zero.

    medium
  13. 306

    Wiggle Sort

    Reorder an array in place so it alternately rises and falls.

    medium
  14. 307

    Find All Duplicates in an Array

    Find every value that appears twice in an array, in place.

    medium

Hard

9 problems
  1. 309

    First Missing Positive

    Find the smallest missing positive integer in O(n) time and O(1) space.

    hard
  2. 310

    Best Time to Buy and Sell Stock III

    Maximize profit across at most two non-overlapping trades.

    hard
  3. 311

    Best Time to Buy and Sell Stock IV

    Maximize profit across at most k non-overlapping trades.

    hard
  4. 312

    Longest Consecutive Sequence

    Find the longest run of consecutive integers in an unsorted array.

    hard
  5. 313

    Russian Doll Envelopes

    Find the longest chain of envelopes that each nest inside the next.

    hard
  6. 314

    Maximum Profit in Job Scheduling

    Pick non-overlapping jobs that maximize total profit.

    hard
  7. 315

    Minimum Number of Operations to Make Array Continuous

    Find the fewest replacements needed to make an array a consecutive run.

    hard
  8. 317

    Count Subarrays With Fixed Bounds

    Count subarrays whose minimum and maximum match two fixed bounds.

    hard
  9. 318

    Minimum Cost to Hire K Workers

    Hire k workers at minimum total cost while respecting wage ratios.

    hard