LeetCodechevron_rightarray math

array math Pattern

111 problems

Pattern pages help build reusable solving frames. Identify signals first, then explain state, transition, and edge handling.

Recognition Signals

  • Focus on in-place array manipulation rather than creating a new matrix.
  • Check if candidate uses both transpose and row reversal, showing understanding of index math.
  • Can the candidate handle the carry and array resizing efficiently?

Solve Flow

  1. 1. Define the active state/window.
  2. 2. Update state while preserving invariants.
  3. 3. Validate with edge-heavy examples.

Common Misses

  • Trying to rotate using an extra matrix, which violates in-place constraint.
  • Forgetting to handle carry-over when incrementing digits.
  • Attempting to divide every number by all smaller numbers instead of using a sieve.

Recommended Ladder

#TitleDifficulty
48

Rotate Image

Rotate an n x n matrix 90 degrees clockwise in-place using array manipulation and mathematical indexing techniques effic…

Medium
66

Plus One

Given a number as an array of digits, increment it by one and return the updated array of digits.

Easy
204

Count Primes

Count all prime numbers less than a given integer n using efficient array and math-based enumeration techniques.

Medium
335

Self Crossing

Determine if a path defined by sequential distances on a 2D plane crosses itself using array and math reasoning.

Hard
384

Shuffle an Array

Shuffle an Array requires designing a class to randomly permute an integer array while ensuring all permutations are equ…

Medium
453

Minimum Moves to Equal Array Elements

Compute the fewest steps to make all elements equal by incrementing n-1 array items, applying array and math reasoning.

Medium
462

Minimum Moves to Equal Array Elements II

Find the minimum moves to equalize all array elements using increments or decrements with array and math techniques.

Medium
477

Total Hamming Distance

Calculate the total Hamming distance between all pairs in an integer array using efficient bit manipulation techniques.

Medium
539

Minimum Time Difference

Calculate the smallest time difference between clock points using array manipulation and mathematical conversions effici…

Medium
587

Erect the Fence

Find the perimeter fence of a garden by determining the outermost trees in a set of given tree coordinates.

Hard
598

Range Addition II

Range Addition II requires counting maximum values in a matrix after incremental operations using array and math reasoni…

Easy
628

Maximum Product of Three Numbers

Find three numbers in an array whose product is the largest using sorting and careful handling of negative values.

Easy
667

Beautiful Arrangement II

Construct a beautiful arrangement of integers from 1 to n with k distinct integers, optimizing for time and space effici…

Medium
775

Global and Local Inversions

Determine if every global inversion in a permutation array is also a local inversion using array and math logic efficien…

Medium
782

Transform to Chessboard

Determine the minimum swaps of rows or columns to convert an n x n binary board into a valid chessboard configuration.

Hard
789

Escape The Ghosts

Escape The Ghosts tests your ability to analyze movements in an infinite grid while racing against ghost positions using…

Medium
810

Chalkboard XOR Game

The Chalkboard XOR Game is a game theory problem involving array manipulation and bitwise XOR, where players alternate e…

Hard
812

Largest Triangle Area

Find the area of the largest triangle formed by three distinct points on a 2D plane.

Easy
843

Guess the Word

Master the Guess the Word problem by applying array manipulation, match-counting math, and strategic interactive guessin…

Hard
883

Projection Area of 3D Shapes

Calculate the projection area of a 3D shape defined by a grid of towers with varying heights.

Easy
891

Sum of Subsequence Widths

Calculate the sum of widths for all subsequences in an integer array using sorting and combinatorial math efficiently.

Hard
892

Surface Area of 3D Shapes

Solve the Surface Area of 3D Shapes problem using array manipulation and mathematical formulas to calculate surface area…

Easy
908

Smallest Range I

Find the smallest score of an array after applying an operation to each element within a given range.

Easy
927

Three Equal Parts

Divide a binary array into three contiguous parts such that each part represents the same integer value in binary, using…

Hard
932

Beautiful Array

Beautiful Array builds a valid permutation by recursively separating odd and even positions so no middle-average triple …

Medium
973

K Closest Points to Origin

Find the k closest points to the origin in a 2D plane using array operations and Euclidean distance calculations efficie…

Medium
989

Add to Array-Form of Integer

Compute the sum of an integer and a number represented as an array, efficiently handling digit carries and array travers…

Easy
1030

Matrix Cells in Distance Order

Compute all matrix cell coordinates sorted by Manhattan distance from a given center using array and math techniques eff…

Easy
1037

Valid Boomerang

Determine if three points on a 2D plane form a boomerang, based on distinctness and non-collinearity.

Easy
1073

Adding Two Negabinary Numbers

Add two numbers represented in negabinary format and return the result in the same format.

Medium
1093

Statistics from a Large Sample

Calculate minimum, maximum, mean, median, and mode from a large sample represented by an array of counts.

Medium
1131

Maximum of Absolute Value Expression

Calculate the largest sum of absolute differences across two arrays and their indices using an efficient pattern-based a…

Medium
1232

Check If It Is a Straight Line

Determine if a series of coordinates form a straight line on a 2D plane using geometry and mathematical principles.

Easy
1250

Check If It Is a Good Array

Determine if a given array of positive integers can generate 1 using integer multiples of any subset, leveraging number …

Hard
1252

Cells with Odd Values in a Matrix

This problem involves updating a matrix based on given indices and counting cells with odd values afterward.

Easy
1266

Minimum Time Visiting All Points

Calculate the minimum seconds required to visit all given 2D points in order using optimal diagonal or straight moves.

Easy
1295

Find Numbers with Even Number of Digits

Count the integers in an array that have an even number of digits using a direct array traversal with digit math.

Easy
1304

Find N Unique Integers Sum up to Zero

Generate an array of n unique integers that sum to zero using a symmetric pairing strategy to ensure balance.

Easy
1352

Product of the Last K Numbers

Design a data structure to efficiently return the product of the last k numbers in a dynamic integer stream using prefix…

Medium
1390

Four Divisors

Compute the sum of all divisors for numbers in an array that have exactly four divisors using array and math techniques.

Medium
1453

Maximum Number of Darts Inside of a Circular Dartboard

Maximize the number of darts on a circular dartboard given dart positions and radius.

Hard
1515

Best Position for a Service Centre

Find the optimal service center position in a city by minimizing the sum of Euclidean distances to all customers.

Hard
1588

Sum of All Odd Length Subarrays

Calculate the sum of all odd-length subarrays in a given integer array using efficient array and math strategies.

Easy
1627

Graph Connectivity With Threshold

In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…

Hard
1685

Sum of Absolute Differences in a Sorted Array

Calculate the sum of absolute differences between each element and others in a sorted array efficiently.

Medium
1806

Minimum Number of Operations to Reinitialize a Permutation

Find the minimum number of operations to reinitialize a permutation of size n using specific operations.

Medium
1819

Number of Different Subsequences GCDs

Given an array of positive integers, find the number of different subsequences' GCDs.

Hard
1822

Sign of the Product of an Array

Determine the sign of a product from an integer array using a single pass without computing the full product.

Easy
1828

Queries on Number of Points Inside a Circle

Determine how many 2D points lie within multiple circles using array iteration and Euclidean distance calculations effic…

Medium
1835

Find XOR Sum of All Pairs Bitwise AND

Compute the XOR sum of all pairwise ANDs between two integer arrays using array and bitwise math techniques efficiently.

Hard
1840

Maximum Building Height

Find the maximum building height in a city given height restrictions for specific buildings.

Hard
1878

Get Biggest Three Rhombus Sums in a Grid

Find the three largest distinct rhombus sums from a given grid using array and math techniques.

Medium
1979

Find Greatest Common Divisor of Array

Find the greatest common divisor of the smallest and largest numbers in an integer array.

Easy
1998

GCD Sort of an Array

The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.

Hard
2028

Find Missing Observations

Given a set of dice rolls, calculate the missing observations based on the mean and return them or determine if it's imp…

Medium
2033

Minimum Operations to Make a Uni-Value Grid

Determine the fewest additions or subtractions of x to make all grid elements identical using array and math logic.

Medium
2125

Number of Laser Beams in a Bank

Calculate total laser beams in a bank floor plan using array counting and math logic between security devices on differe…

Medium
2183

Count Array Pairs Divisible by K

Count Array Pairs Divisible by K requires counting index pairs whose products are divisible by a given number k.

Hard
2217

Find Palindrome With Fixed Length

Find the smallest palindromes of a given length for specific queries with mathematical and array manipulation.

Medium
2221

Find Triangular Sum of an Array

The problem asks for calculating the triangular sum of an array through repeated pairwise summation.

Medium
2280

Minimum Lines to Represent a Line Chart

Determine the fewest lines needed to accurately connect stock price points in a line chart using array and math reasonin…

Medium
2317

Maximum XOR After Operations

Maximize the bitwise XOR of an array after applying a special operation with non-negative integers multiple times.

Medium
2344

Minimum Deletions to Make Array Divisible

Find the minimum number of deletions to make the smallest element in nums divide all elements of numsDivide.

Hard
2348

Number of Zero-Filled Subarrays

Given an array of integers, count the subarrays that consist entirely of 0s.

Medium
2447

Number of Subarrays With GCD Equal to K

Count the number of subarrays with GCD equal to a given value k from a list of integers.

Medium
2455

Average Value of Even Numbers That Are Divisible by Three

Find the average of even numbers divisible by 3 from an array of positive integers.

Easy
2470

Number of Subarrays With LCM Equal to K

Find the number of subarrays in an array where the least common multiple (LCM) of the subarray equals a given integer k.

Medium
2527

Find Xor-Beauty of Array

Find the xor-beauty of an array by XORing the effective values of all possible triplets of indices.

Medium
2535

Difference Between Element Sum and Digit Sum of an Array

Find the absolute difference between element sum and digit sum of an array of integers.

Easy
2575

Find the Divisibility Array of a String

Calculate the divisibility array for a string by checking if prefixes are divisible by a given number.

Medium
2614

Prime In Diagonal

Find the largest prime number located on any diagonal of a square matrix using array iteration and prime checking techni…

Easy
2654

Minimum Number of Operations to Make All Array Elements Equal to 1

Find the minimum number of operations to transform every element of a positive integer array into 1 using gcd operations…

Medium
2709

Greatest Common Divisor Traversal

Determine if every index in an array can be reached from any other using traversals based on greatest common divisors.

Hard
2761

Prime Pairs With Target Sum

Find all prime number pairs that sum up to a given integer n using an efficient sieve-based array approach.

Medium
2862

Maximum Element-Sum of a Complete Subset of Indices

Given a 1-indexed array, select a subset where indices' product is a perfect square, then return the maximum sum.

Hard
2946

Matrix Similarity After Cyclic Shifts

Determine if a matrix returns to its original state after performing cyclic row shifts k times using array and math patt…

Easy
2954

Count the Number of Infection Sequences

Calculate all valid infection sequences in a line by using array positions and combinatorial math efficiently for n peop…

Hard
2961

Double Modular Exponentiation

Solve the Double Modular Exponentiation problem by applying array manipulation and modular arithmetic to find good indic…

Medium
3024

Type of Triangle

Determine the type of triangle from a three-element array using side sums and equality checks efficiently in constant ti…

Easy
3025

Find the Number of Ways to Place People I

Calculate how many valid pairs of points can be formed on a 2D plane using array and math enumeration techniques efficie…

Medium
3027

Find the Number of Ways to Place People II

Calculate all valid placements of people on a 2D grid ensuring Alice can fence herself with Bob without enclosing others…

Hard
3047

Find the Largest Area of Square Inside Two Rectangles

Find the largest square area that can fit inside the intersection of two or more rectangles in a 2D plane.

Medium
3079

Find the Sum of Encrypted Integers

Compute the sum of encrypted integers by replacing each digit with the largest digit, combining array traversal with dig…

Easy
3101

Count Alternating Subarrays

Count all alternating subarrays in a binary array efficiently using array patterns and simple mathematical reasoning.

Medium
3102

Minimize Manhattan Distances

Compute the minimum maximum Manhattan distance by removing one point using array math and geometry insights efficiently.

Hard
3115

Maximum Prime Difference

Calculate the largest index gap between prime numbers in an array using array traversal and number theory insights effic…

Medium
3179

Find the N-th Value After K Seconds

Solve for the N-th value after K seconds by simulating array updates and using prefix sum techniques.

Medium
3190

Find Minimum Operations to Make All Elements Divisible by Three

Find the minimum number of operations to make all elements in an array divisible by three.

Easy
3232

Find if Digit Game Can Be Won

Determine if Alice can guarantee a win in a game by selectively summing single or double-digit numbers from an array.

Easy
3233

Find the Count of Numbers Which Are Not Special

Count the numbers between two integers that are not special, where special numbers are squares of primes.

Medium
3235

Check if the Rectangle Corner Is Reachable

Determine if there is a valid path from the bottom-left to top-right of a rectangle while avoiding circles.

Hard
3264

Final Array State After K Multiplication Operations I

Solve the problem of determining the final state of an array after multiple multiplication operations using a priority q…

Easy
3283

Maximum Number of Moves to Kill All Pawns

Calculate the maximum number of moves to eliminate all pawns using BFS, bitmasking, and precise array position math effi…

Hard
3300

Minimum Element After Replacement With Digit Sum

Replace each number with its digit sum and return the smallest resulting value, using array plus math techniques efficie…

Easy
3334

Find the Maximum Factor Score of Array

Calculate the maximum factor score of an integer array by optionally removing one element using LCM and GCD computations…

Medium
3380

Maximum Area Rectangle With Point Constraints I

Find the maximum area of a rectangle formed by given points on a plane with unique coordinates.

Medium
3382

Maximum Area Rectangle With Point Constraints II

Find the largest rectangle on a plane using given points while avoiding any interior points and optimizing with math and…

Hard
3432

Count Partitions with Even Sum Difference

Count the number of partitions with an even sum difference from an array of integers.

Easy
3433

Count Mentions Per User

Calculate how many times each user is mentioned across MESSAGE events, accounting for offline and online statuses effici…

Medium
3468

Find the Number of Copy Arrays

Find the number of possible arrays by leveraging bounds and math in this array-based problem.

Medium
3470

Permutations IV

Find the k-th alternating permutation of numbers 1 to n, ensuring no adjacent numbers share parity, using array and math…

Hard
3495

Minimum Operations to Make Array Elements Zero

Minimize operations to reduce array elements to zero, focusing on array manipulation, math, and bit operations for effic…

Hard
3512

Minimum Operations to Make Array Sum Divisible by K

This problem asks you to find the minimum operations to make the sum of an array divisible by a given integer k.

Easy
3513

Number of Unique XOR Triplets I

Calculate all unique XOR triplet values in a permutation array using array traversal and bit manipulation techniques eff…

Medium
3514

Number of Unique XOR Triplets II

Count all unique XOR results from triplets in an integer array using array traversal and bit manipulation techniques eff…

Medium
3525

Find X Value of Array II

The "Find X Value of Array II" problem requires calculating the number of ways to remove a suffix from an array such tha…

Hard
3550

Smallest Index With Digit Sum Equal to Index

Find the smallest index in an array where the sum of the digits equals the index.

Easy
3569

Maximize Count of Distinct Primes After Split

Compute the maximum number of distinct prime numbers after sequentially updating array elements with efficient preproces…

Hard
3574

Maximize Subarray GCD Score

Maximize Subarray GCD Score focuses on maximizing a subarray's score by using at most k doubling operations on an array …

Hard
3577

Count the Number of Computer Unlocking Permutations

Calculate the total valid unlocking sequences for computers based on their complexity using array and combinatorics logi…

Medium
3618

Split Array by Prime Indices

Split Array by Prime Indices challenges you to separate elements at prime positions and minimize the absolute sum differ…

Medium

Related Topics

Array plus Math LeetCode Pattern: 111 Solutions