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. Define the active state/window.
- 2. Update state while preserving invariants.
- 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
Rotate Image
Rotate an n x n matrix 90 degrees clockwise in-place using array manipulation and mathematical indexing techniques effic…
Plus One
Given a number as an array of digits, increment it by one and return the updated array of digits.
Count Primes
Count all prime numbers less than a given integer n using efficient array and math-based enumeration techniques.
Self Crossing
Determine if a path defined by sequential distances on a 2D plane crosses itself using array and math reasoning.
Shuffle an Array
Shuffle an Array requires designing a class to randomly permute an integer array while ensuring all permutations are equ…
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.
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.
Total Hamming Distance
Calculate the total Hamming distance between all pairs in an integer array using efficient bit manipulation techniques.
Minimum Time Difference
Calculate the smallest time difference between clock points using array manipulation and mathematical conversions effici…
Erect the Fence
Find the perimeter fence of a garden by determining the outermost trees in a set of given tree coordinates.
Range Addition II
Range Addition II requires counting maximum values in a matrix after incremental operations using array and math reasoni…
Maximum Product of Three Numbers
Find three numbers in an array whose product is the largest using sorting and careful handling of negative values.
Beautiful Arrangement II
Construct a beautiful arrangement of integers from 1 to n with k distinct integers, optimizing for time and space effici…
Global and Local Inversions
Determine if every global inversion in a permutation array is also a local inversion using array and math logic efficien…
Transform to Chessboard
Determine the minimum swaps of rows or columns to convert an n x n binary board into a valid chessboard configuration.
Escape The Ghosts
Escape The Ghosts tests your ability to analyze movements in an infinite grid while racing against ghost positions using…
Chalkboard XOR Game
The Chalkboard XOR Game is a game theory problem involving array manipulation and bitwise XOR, where players alternate e…
Largest Triangle Area
Find the area of the largest triangle formed by three distinct points on a 2D plane.
Guess the Word
Master the Guess the Word problem by applying array manipulation, match-counting math, and strategic interactive guessin…
Projection Area of 3D Shapes
Calculate the projection area of a 3D shape defined by a grid of towers with varying heights.
Sum of Subsequence Widths
Calculate the sum of widths for all subsequences in an integer array using sorting and combinatorial math efficiently.
Surface Area of 3D Shapes
Solve the Surface Area of 3D Shapes problem using array manipulation and mathematical formulas to calculate surface area…
Smallest Range I
Find the smallest score of an array after applying an operation to each element within a given range.
Three Equal Parts
Divide a binary array into three contiguous parts such that each part represents the same integer value in binary, using…
Beautiful Array
Beautiful Array builds a valid permutation by recursively separating odd and even positions so no middle-average triple …
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…
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…
Matrix Cells in Distance Order
Compute all matrix cell coordinates sorted by Manhattan distance from a given center using array and math techniques eff…
Valid Boomerang
Determine if three points on a 2D plane form a boomerang, based on distinctness and non-collinearity.
Adding Two Negabinary Numbers
Add two numbers represented in negabinary format and return the result in the same format.
Statistics from a Large Sample
Calculate minimum, maximum, mean, median, and mode from a large sample represented by an array of counts.
Maximum of Absolute Value Expression
Calculate the largest sum of absolute differences across two arrays and their indices using an efficient pattern-based a…
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.
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 …
Cells with Odd Values in a Matrix
This problem involves updating a matrix based on given indices and counting cells with odd values afterward.
Minimum Time Visiting All Points
Calculate the minimum seconds required to visit all given 2D points in order using optimal diagonal or straight moves.
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.
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.
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…
Four Divisors
Compute the sum of all divisors for numbers in an array that have exactly four divisors using array and math techniques.
Maximum Number of Darts Inside of a Circular Dartboard
Maximize the number of darts on a circular dartboard given dart positions and radius.
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.
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.
Graph Connectivity With Threshold
In 'Graph Connectivity With Threshold,' determine if cities are connected based on common divisors exceeding a threshold…
Sum of Absolute Differences in a Sorted Array
Calculate the sum of absolute differences between each element and others in a sorted array efficiently.
Minimum Number of Operations to Reinitialize a Permutation
Find the minimum number of operations to reinitialize a permutation of size n using specific operations.
Number of Different Subsequences GCDs
Given an array of positive integers, find the number of different subsequences' GCDs.
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.
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…
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.
Maximum Building Height
Find the maximum building height in a city given height restrictions for specific buildings.
Get Biggest Three Rhombus Sums in a Grid
Find the three largest distinct rhombus sums from a given grid using array and math techniques.
Find Greatest Common Divisor of Array
Find the greatest common divisor of the smallest and largest numbers in an integer array.
GCD Sort of an Array
The GCD Sort problem challenges you to sort an array using a specific gcd-based swap method.
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…
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.
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…
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.
Find Palindrome With Fixed Length
Find the smallest palindromes of a given length for specific queries with mathematical and array manipulation.
Find Triangular Sum of an Array
The problem asks for calculating the triangular sum of an array through repeated pairwise summation.
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…
Maximum XOR After Operations
Maximize the bitwise XOR of an array after applying a special operation with non-negative integers multiple times.
Minimum Deletions to Make Array Divisible
Find the minimum number of deletions to make the smallest element in nums divide all elements of numsDivide.
Number of Zero-Filled Subarrays
Given an array of integers, count the subarrays that consist entirely of 0s.
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.
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.
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.
Find Xor-Beauty of Array
Find the xor-beauty of an array by XORing the effective values of all possible triplets of indices.
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.
Find the Divisibility Array of a String
Calculate the divisibility array for a string by checking if prefixes are divisible by a given number.
Prime In Diagonal
Find the largest prime number located on any diagonal of a square matrix using array iteration and prime checking techni…
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…
Greatest Common Divisor Traversal
Determine if every index in an array can be reached from any other using traversals based on greatest common divisors.
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.
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.
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…
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…
Double Modular Exponentiation
Solve the Double Modular Exponentiation problem by applying array manipulation and modular arithmetic to find good indic…
Type of Triangle
Determine the type of triangle from a three-element array using side sums and equality checks efficiently in constant ti…
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…
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…
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.
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…
Count Alternating Subarrays
Count all alternating subarrays in a binary array efficiently using array patterns and simple mathematical reasoning.
Minimize Manhattan Distances
Compute the minimum maximum Manhattan distance by removing one point using array math and geometry insights efficiently.
Maximum Prime Difference
Calculate the largest index gap between prime numbers in an array using array traversal and number theory insights effic…
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.
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.
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.
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.
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.
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…
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…
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…
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…
Maximum Area Rectangle With Point Constraints I
Find the maximum area of a rectangle formed by given points on a plane with unique coordinates.
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…
Count Partitions with Even Sum Difference
Count the number of partitions with an even sum difference from an array of integers.
Count Mentions Per User
Calculate how many times each user is mentioned across MESSAGE events, accounting for offline and online statuses effici…
Find the Number of Copy Arrays
Find the number of possible arrays by leveraging bounds and math in this array-based problem.
Permutations IV
Find the k-th alternating permutation of numbers 1 to n, ensuring no adjacent numbers share parity, using array and math…
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…
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.
Number of Unique XOR Triplets I
Calculate all unique XOR triplet values in a permutation array using array traversal and bit manipulation techniques eff…
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…
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…
Smallest Index With Digit Sum Equal to Index
Find the smallest index in an array where the sum of the digits equals the index.
Maximize Count of Distinct Primes After Split
Compute the maximum number of distinct prime numbers after sequentially updating array elements with efficient preproces…
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 …
Count the Number of Computer Unlocking Permutations
Calculate the total valid unlocking sequences for computers based on their complexity using array and combinatorics logi…
Split Array by Prime Indices
Split Array by Prime Indices challenges you to separate elements at prime positions and minimize the absolute sum differ…