Array Interview Questions

Index-based sequences, scanning, and in-place mutation patterns used in most interviews.

433 problems

#Title
26Remove Duplicates from Sorted Array
27Remove Element
31Next Permutation
41First Missing Positive
48Rotate Image
54Spiral Matrix
59Spiral Matrix II
66Plus One
73Set Matrix Zeroes
80Remove Duplicates from Sorted Array II
118Pascal's Triangle
119Pascal's Triangle II
121Best Time to Buy and Sell Stock
128Longest Consecutive Sequence
157Read N Characters Given Read4
158Read N Characters Given Read4 II - Call multiple times
163Missing Ranges
169Majority Element
189Rotate Array
215Kth Largest Element in an Array
228Summary Ranges
229Majority Element II
238Product of Array Except Self
240Search a 2D Matrix II
243Shortest Word Distance
245Shortest Word Distance III
251Flatten 2D Vector
277Find the Celebrity
289Game of Life
293Flip Game
296Best Meeting Point
311Sparse Matrix Multiplication
334Increasing Triplet Subsequence
370Range Addition
384Shuffle an Array
396Rotate Function
412Fizz Buzz
414Third Maximum Number
419Battleships in a Board
422Valid Word Square
442Find All Duplicates in an Array
448Find All Numbers Disappeared in an Array
462Minimum Moves to Equal Array Elements II
463Island Perimeter
485Max Consecutive Ones
487Max Consecutive Ones II
495Teemo Attacking
498Diagonal Traverse
506Relative Ranks
531Lonely Pixel I
533Lonely Pixel II
565Array Nesting
566Reshape the Matrix
581Shortest Unsorted Continuous Subarray
605Can Place Flowers
624Maximum Distance in Arrays
643Maximum Average Subarray I
644Maximum Average Subarray II
661Image Smoother
665Non-decreasing Array
667Beautiful Arrangement II
670Maximum Swap
674Longest Continuous Increasing Subsequence
683K Empty Slots
697Degree of an Array
713Subarray Product Less Than K
7171-bit and 2-bit Characters
723Candy Crush
724Find Pivot Index
729My Calendar I
731My Calendar II
732My Calendar III
747Largest Number At Least Twice of Others
755Pour Water
766Toeplitz Matrix
768Max Chunks To Make Sorted II
769Max Chunks To Make Sorted
778Swim in Rising Water
792Number of Matching Subsequences
794Valid Tic-Tac-Toe State
795Number of Subarrays with Bounded Maximum
803Bricks Falling When Hit
807Max Increase to Keep City Skyline
821Shortest Distance to a Character
830Positions of Large Groups
832Flipping an Image
835Image Overlap
840Magic Squares In Grid
842Split Array into Fibonacci Sequence
845Longest Mountain in Array
849Maximize Distance to Closest Person
860Lemonade Change
867Transpose Matrix
885Spiral Matrix III
888Fair Candy Swap
896Monotonic Array
905Sort Array By Parity
909Snakes and Ladders
915Partition Array into Disjoint Intervals
918Maximum Sum Circular Subarray
922Sort Array By Parity II
9233Sum With Multiplicity
927Three Equal Parts
932Beautiful Array
941Valid Mountain Array
945Minimum Increment to Make Array Unique
947Most Stones Removed with Same Row or Column
949Largest Time for Given Digits
950Reveal Cards In Increasing Order
952Largest Component Size by Common Factor
954Array of Doubled Pairs
961N-Repeated Element in Size 2N Array
978Longest Turbulent Subarray
985Sum of Even Numbers After Queries
989Add to Array-Form of Integer
997Find the Town Judge
999Available Captures for Rook
1002Find Common Characters
1007Minimum Domino Rotations For Equal Row
1010Pairs of Songs With Total Durations Divisible by 60
1013Partition Array Into Three Parts With Equal Sum
1014Best Sightseeing Pair
1018Binary Prefix Divisible By 5
1030Matrix Cells in Distance Order
1031Maximum Sum of Two Non-Overlapping Subarrays
1051Height Checker
1052Grumpy Bookstore Owner
1072Flip Columns For Maximum Number of Equal Rows
1074Number of Submatrices That Sum to Target
1085Sum of Digits in the Minimum Number
1089Duplicate Zeros
1093Statistics from a Large Sample
1099Two Sum Less Than K
1109Corporate Flight Bookings
1144Decrease Elements To Make Array Zigzag
1184Distance Between Bus Stops
1200Minimum Absolute Difference
1222Queens That Can Attack the King
1252Cells with Odd Values in a Matrix
1260Shift 2D Grid
1267Count Servers that Communicate
1275Find Winner on a Tic Tac Toe Game
1295Find Numbers with Even Number of Digits
1299Replace Elements with Greatest Element on Right Side
1304Find N Unique Integers Sum up to Zero
1313Decompress Run-Length Encoded List
1329Sort the Matrix Diagonally
1331Rank Transform of an Array
1333Filter Restaurants by Vegan-Friendly, Price and Distance
1337The K Weakest Rows in a Matrix
1343Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold
1346Check If N and Its Double Exist
1351Count Negative Numbers in a Sorted Matrix
1375Bulb Switcher III
1380Lucky Numbers in a Matrix
1389Create Target Array in the Given Order
1394Find Lucky Integer in an Array
1399Count Largest Group
1404Number of Steps to Reduce a Number in Binary Representation to One
1413Minimum Value to Get Positive Step by Step Sum
1426Counting Elements
1427Perform String Shifts
1428Leftmost Column with at Least a One
1431Kids With the Greatest Number of Candies
1437Check If All 1's Are at Least Length K Places Away
1450Number of Students Doing Homework at a Given Time
1460Make Two Arrays Equal by Reversing Sub-arrays
1464Maximum Product of Two Elements in an Array
1465Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
1470Shuffle the Array
1471The k Strongest Values in an Array
1475Final Prices With a Special Discount in a Shop
1480Running Sum of 1d Array
1491Average Salary Excluding the Minimum and Maximum Salary
1502Can Make Arithmetic Progression From Sequence
1503Last Moment Before All Ants Fall Out of a Plank
1534Count Good Triplets
1535Find the Winner of an Array Game
1538Guess the Majority in a Hidden Array
1550Three Consecutive Odds
1559Detect Cycles in 2D Grid
1560Most Visited Sector in a Circular Track
1562Find Latest Group of Size M
1566Detect Pattern of Length M Repeated K or More Times
1572Matrix Diagonal Sum
1574Shortest Subarray to be Removed to Make Array Sorted
1582Special Positions in a Binary Matrix
1583Count Unhappy Friends
1619Mean of Array After Removing Some Elements
1629Slowest Key
1646Get Maximum in Generated Array
1652Defuse the Bomb
1672Richest Customer Wealth
1700Number of Students Unable to Eat Lunch
1701Average Waiting Time
1706Where Will the Ball Fall
1714Sum Of Special Evenly-Spaced Elements In Array
1726Tuple with Same Product
1732Find the Highest Altitude
1738Find Kth Largest XOR Coordinate Value
1742Maximum Number of Balls in a Box
1752Check if Array Is Sorted and Rotated
1755Closest Subsequence Sum
1773Count Items Matching a Rule
1779Find Nearest Point That Has the Same X or Y Coordinate
1800Maximum Ascending Subarray Sum
1826Faulty Sensor
1848Minimum Distance to the Target Element
1861Rotating the Box
1869Longer Contiguous Segments of Ones than Zeros
1878Get Biggest Three Rhombus Sums in a Grid
1886Determine Whether Matrix Can Be Obtained By Rotation
1895Largest Magic Square
1906Minimum Absolute Difference Queries
1909Remove One Element to Make the Array Strictly Increasing
1914Cyclically Rotating a Grid
1920Build Array from Permutation
1929Concatenation of Array
1940Longest Common Subsequence Between Sorted Arrays
1958Check if Move is Legal
1966Binary Searchable Numbers in an Unsorted Array
1970Last Day Where You Can Still Cross
1983Widest Pair of Indices With Equal Range Sum
1991Find the Middle Index in Array
1992Find All Groups of Farmland
1998GCD Sort of an Array
2007Find Original Array From Doubled Array
2011Final Value of Variable After Performing Operations
2012Sum of Beauty in the Array
2016Maximum Difference Between Increasing Elements
2017Grid Game
2018Check if Word Can Be Placed In Crossword
2022Convert 1D Array Into 2D Array
2033Minimum Operations to Make a Uni-Value Grid
2035Partition Array Into Two Arrays to Minimize Sum Difference
2038Remove Colored Pieces if Both Neighbors are the Same Color
2055Plates Between Candles
2057Smallest Index With Equal Value
2075Decode the Slanted Ciphertext
2078Two Furthest Houses With Different Colors
2079Watering Plants
2098Subsequence of Size K With the Largest Even Sum
2099Find Subsequence of Length K With the Largest Sum
2100Find Good Days to Rob the Bank
2106Maximum Fruits Harvested After at Most K Steps
2113Elements in Array After Removing and Replacing Elements
2121Intervals Between Identical Elements
2122Recover the Original Array
2128Remove All Ones With Row and Column Flips
2132Stamping the Grid
2155All Divisions With the Highest Score of a Binary Array
2194Cells in a Range on an Excel Sheet
2210Count Hills and Valleys in an Array
2219Maximum Sum Score of Array
2237Count Positions on Street With Required Brightness
2239Find Closest Number to Zero
2245Maximum Trailing Zeros in a Cornered Path
2256Minimum Average Difference
2270Number of Ways to Split Array
2271Maximum White Tiles Covered by a Carpet
2274Maximum Consecutive Floors Without Special Floors
2293Min Max Game
2319Check if Matrix Is X-Matrix
2326Spiral Matrix IV
2373Largest Local Values in a Matrix
2382Maximum Segment Sum After Removals
2391Minimum Amount of Time to Collect Garbage
2406Divide Intervals Into Minimum Number of Groups
2407Longest Increasing Subsequence II
2428Maximum Sum of an Hourglass
2432The Employee That Worked on the Longest Task
2433Find The Original Array of Prefix Xor
2438Range Product Queries of Powers
2446Determine if Two Events Have Conflict
2460Apply Operations to an Array
2482Difference Between Ones and Zeros in Row and Column
2500Delete Greatest Value in Each Row
2515Shortest Distance to Target String in a Circular Array
2535Difference Between Element Sum and Digit Sum of an Array
2536Increment Submatrices by One
2553Separate the Digits in an Array
2559Count Vowel Strings in Ranges
2569Handling Sum Queries After Update
2574Left and Right Sum Differences
2580Count Ways to Group Overlapping Ranges
2639Find the Width of Columns of a Grid
2640Find the Score of All Prefixes of an Array
2643Row With Maximum Ones
2644Find the Maximum Divisibility Score
2655Find Maximal Uncovered Ranges
2660Determine the Winner of a Bowling Game
2672Number of Adjacent Elements With the Same Color
2683Neighboring Bitwise XOR
2711Difference of Number of Distinct Values on Diagonals
2717Semi-Ordered Permutation
2733Neither Minimum nor Maximum
2760Longest Even Odd Subarray With Threshold
2765Longest Alternating Subarray
2782Number of Unique Categories
2798Number of Employees Who Met the Target
2848Points That Intersect With Cars
2855Minimum Right Shifts to Sort the Array
2873Maximum Value of an Ordered Triplet I
2874Maximum Value of an Ordered Triplet II
2903Find Indices With Index and Value Difference I
2905Find Indices With Index and Value Difference II
2906Construct Product Matrix
2908Minimum Sum of Mountain Triplets I
2909Minimum Sum of Mountain Triplets II
2923Find Champion I
2946Matrix Similarity After Cyclic Shifts
2951Find the Peaks
2965Find Missing and Repeated Values
2966Divide Array Into Arrays With Max Difference
3000Maximum Area of Longest Diagonal Rectangle
3009Maximum Number of Intersections on the Chart
3010Divide an Array Into Subarrays With Minimum Cost I
3015Count the Number of Houses at a Certain Distance I
3017Count the Number of Houses at a Certain Distance II
3026Maximum Good Subarray Sum
3028Ant on the Boundary
3030Find the Grid of Region Average
3033Modify the Matrix
3038Maximum Number of Operations With the Same Score I
3065Minimum Operations to Exceed Threshold Value I
3069Distribute Elements Into Two Arrays I
3070Count Submatrices with Top-Left Element and Sum Less Than k
3071Minimum Operations to Write the Letter Y on a Grid
3079Find the Sum of Encrypted Integers
3096Minimum Levels to Gain More Points
3105Longest Strictly Increasing or Strictly Decreasing Subarray
3127Make a Square with the Same Color
3131Find the Integer Added to Array I
3142Check if Grid Satisfies Conditions
3147Taking Maximum Energy From the Mystic Dungeon
3151Special Array I
3152Special Array II
3153Sum of Digit Differences of All Pairs
3159Find Occurrences of an Element in an Array
3173Bitwise OR of Adjacent Elements
3187Peaks in Array
3195Find the Minimum Area to Cover All Ones I
3224Minimum Array Changes to Make Differences Equal
3279Maximum Total Area Occupied by Pistons
3285Find Indices of Stable Mountains
3300Minimum Element After Replacement With Digit Sum
3330Find the Original Typed String I
3334Find the Maximum Factor Score of Array
3349Adjacent Increasing Subarrays Detection I
3350Adjacent Increasing Subarrays Detection II
3353Minimum Total Operations
3354Make Array Elements Equal to Zero
3355Zero Array Transformation I
3361Shift Distance Between Two Strings
3379Transformed Array
3380Maximum Area Rectangle With Point Constraints I
3382Maximum Area Rectangle With Point Constraints II
3386Button with Longest Push Time
3392Count Subarrays of Length Three With a Condition
3400Maximum Number of Matching Indices After Right Shifts
3417Zigzag Grid Traversal With Skip
3423Maximum Difference Between Adjacent Elements in a Circular Array
3427Sum of Variable Length Subarrays
3432Count Partitions with Even Sum Difference
3440Reschedule Meetings for Maximum Free Time II
3446Sort Matrix by Diagonals
3452Sum of Good Numbers
3467Transform Array by Parity
3502Minimum Cost to Reach Every Position
3514Number of Unique XOR Triplets II
3531Count Covered Buildings
3537Fill a Special Grid
3540Minimum Time to Visit All Houses
3546Equal Sum Grid Partition I
3548Equal Sum Grid Partition II
3549Multiply Two Polynomials
3550Smallest Index With Digit Sum Equal to Index
3569Maximize Count of Distinct Primes After Split
3637Trionic Array I
3643Flip Square Submatrix Vertically
3653XOR After Range Multiplication Queries I
3655XOR After Range Multiplication Queries II
3674Minimum Operations to Equalize Array
3683Earliest Time to Finish One Task
3687Library Late Fee Calculator
3688Bitwise OR of Even Numbers in an Array
3696Maximum Distance Between Unequal Words in Array I
3700Number of ZigZag Arrays II
3701Compute Alternating Sum
3706Maximum Distance Between Unequal Words in Array II
3707Equal Score Substrings
3708Longest Fibonacci Subarray
3719Longest Balanced Subarray I
3721Longest Balanced Subarray II
3736Minimum Moves to Equal Array Elements III
3737Count Subarrays With Majority Element I
3738Longest Non-Decreasing Subarray After Replacing at Most One Element
3739Count Subarrays With Majority Element II
3751Total Waviness of Numbers in Range I
3756Concatenate Non-Zero Digits and Multiply by Sum II
3762Minimum Operations to Equalize Subarrays
3774Absolute Difference Between Maximum and Minimum K Elements
3788Maximum Score of a Split
3809Best Reachable Tower
3814Maximum Capacity Within Budget
3818Minimum Prefix Removal to Make Array Strictly Increasing
3819Rotate Non Negative Elements
3833Count Dominant Indices
3861Minimum Capacity Box
3862Find the Smallest Balanced Index
3865Reverse K Subarrays
3880Minimum Absolute Difference Between Two Values
3886Sum of Sortable Integers
3898Find the Degree of Each Vertex
3903Smallest Stable Index I
3904Smallest Stable Index II
3907Count Smaller Elements With Opposite Parity
3909Compare Sums of Bitonic Parts
3912Valid Elements in an Array
3918Sum of Primes Between Number and Its Reverse
3925Concatenate Array With Reverse
3933Largest Local Values in a Matrix II
3936Minimum Swaps to Move Zeros to End
3938Maximum Path Intersection Sum in a Grid
3940Limit Occurrences in Sorted Array
3942Minimum Operations to Sort a Permutation
3943Number of Pairs After Increment
3951Minimum Energy to Maintain Brightness
3963Create Grid With Exactly One Path
3978Unique Middle Element
3979Maximum Valid Pair Sum
3982Sum of Integers with Maximum Digit Range
3985Palindromic Subarray Sum