Simulation LeetCode Problems: All 144, With Python Solutions

Every problem in this library that LeetCode tags Simulation 144 in total, 132 of them with a complete Python solution, a worked example and the time and space complexity of the approach.

  • 144 problems
  • 57 Easy
  • 77 Medium
  • 10 Hard

Simulation problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Easy (57)

#ProblemDifficultyTopics
67Add BinaryEasyBit Manipulation, Math, String +1
258Add DigitsEasyMath, Number Theory, Simulation
412Fizz BuzzEasyMath, String, Simulation
415Add StringsEasyMath, String, Simulation
495Teemo AttackingEasyArray, Simulation
566Reshape the MatrixEasyArray, Matrix, Simulation
657Robot Return to OriginEasyString, Simulation
682Baseball GameEasyStack, Array, Simulation
832Flipping an ImageEasyBit Manipulation, Array, Two Pointers +2
844Backspace String CompareEasyStack, Two Pointers, String +1
867Transpose MatrixEasyArray, Matrix, Simulation
999Available Captures for RookEasyArray, Matrix, Simulation
1103Distribute Candies to PeopleEasyMath, Simulation
1252Cells with Odd Values in a MatrixEasyArray, Math, Simulation
1260Shift 2D GridEasyArray, Matrix, Simulation
1275Find Winner on a Tic Tac Toe GameEasyArray, Hash Table, Matrix +1
1389Create Target Array in the Given OrderEasyArray, Simulation
1518Water BottlesEasyMath, Simulation
1560Most Visited Sector in a Circular TrackEasyArray, Simulation
1603Design Parking SystemEasyDesign, Counting, Simulation
1646Get Maximum in Generated ArrayEasyArray, Simulation
1688Count of Matches in TournamentEasyMath, Simulation
1700Number of Students Unable to Eat LunchEasyStack, Queue, Array +1
1920Build Array from PermutationEasyArray, Simulation
1929Concatenation of ArrayEasyArray, Simulation
1945Sum of Digits of String After ConvertEasyString, Simulation
2011Final Value of Variable After Performing OperationsEasyArray, String, Simulation
2022Convert 1D Array Into 2D ArrayEasyArray, Matrix, Simulation
2073Time Needed to Buy TicketsEasyQueue, Array, Simulation
2138Divide a String Into Groups of Size kEasyString, Simulation
2154Keep Multiplying Found Values by TwoEasyArray, Hash Table, Sorting +1
2169Count Operations to Obtain ZeroEasyMath, Simulation
2180Count Integers With Even Digit SumEasyMath, Simulation
2243Calculate Digit Sum of a StringEasyString, Simulation
2293Min Max GameEasyArray, Simulation
2303Calculate Amount Paid in TaxesEasyArray, Simulation
2357Make Array Zero by Subtracting Equal AmountsEasyGreedy, Array, Hash Table +3
2460Apply Operations to an ArrayEasyArray, Two Pointers, Simulation
2500Delete Greatest Value in Each RowEasyArray, Matrix, Sorting +2
2549Count Distinct Numbers on BoardEasyArray, Hash Table, Math +1
2553Separate the Digits in an ArrayEasyArray, Simulation
2558Take Gifts From the Richest PileEasyArray, Simulation, Heap (Priority Queue)
2562Find the Array Concatenation ValueEasyArray, Two Pointers, Simulation
2582Pass the PillowEasyMath, Simulation
2660Determine the Winner of a Bowling GameEasyArray, Simulation
2682Find the Losers of the Circular GameEasyArray, Hash Table, Simulation
2696Minimum String Length After Removing SubstringsEasyStack, String, Simulation
2717Semi-Ordered PermutationEasyArray, Simulation
2739Total Distance TraveledEasyMath, Simulation
2744Find Maximum Number of String PairsEasyArray, Hash Table, String +1
2810Faulty KeyboardEasyString, Simulation
2899Last Visited IntegersEasyArray, Simulation
2946Matrix Similarity After Cyclic ShiftsEasyArray, Math, Matrix +1
2960Count Tested Devices After Test OperationsEasyArray, Counting, Simulation
2974Minimum Number GameEasyArray, Sorting, Simulation +1
157Read N Characters Given Read4PremiumEasyArray, Interactive, Simulation
1243Array TransformationPremiumEasyArray, Simulation

Medium (77)

#ProblemDifficultyTopics
43Multiply StringsMediumMath, String, Simulation
54Spiral MatrixMediumArray, Matrix, Simulation
59Spiral Matrix IIMediumArray, Matrix, Simulation
289Game of LifeMediumArray, Matrix, Simulation
498Diagonal TraverseMediumArray, Matrix, Simulation
537Complex Number MultiplicationMediumMath, String, Simulation
592Fraction Addition and SubtractionMediumMath, String, Simulation
640Solve the EquationMediumMath, String, Simulation
735Asteroid CollisionMediumStack, Array, Simulation
874Walking Robot SimulationMediumArray, Hash Table, Simulation
885Spiral Matrix IIIMediumArray, Matrix, Simulation
946Validate Stack SequencesMediumStack, Array, Simulation
950Reveal Cards In Increasing OrderMediumQueue, Array, Sorting +1
985Sum of Even Numbers After QueriesMediumArray, Simulation
1006Clumsy FactorialMediumStack, Math, Simulation
1041Robot Bounded In CircleMediumMath, String, Simulation
1094Car PoolingMediumArray, Prefix Sum, Sorting +2
1222Queens That Can Attack the KingMediumArray, Matrix, Simulation
1324Print Words VerticallyMediumArray, String, Simulation
1404Number of Steps to Reduce a Number in Binary Representation to OneMediumBit Manipulation, String, Simulation
1409Queries on a Permutation With KeyMediumBinary Indexed Tree, Array, Simulation
1441Build an Array With Stack OperationsMediumStack, Array, Simulation
1503Last Moment Before All Ants Fall Out of a PlankMediumBrainteaser, Array, Simulation
1535Find the Winner of an Array GameMediumArray, Simulation
1545Find Kth Bit in Nth Binary StringMediumRecursion, String, Simulation
1562Find Latest Group of Size MMediumArray, Hash Table, Binary Search +1
1583Count Unhappy FriendsMediumArray, Simulation
1599Maximum Profit of Operating a Centennial WheelMediumArray, Simulation
1680Concatenation of Consecutive Binary NumbersMediumBit Manipulation, Math, Simulation
1701Average Waiting TimeMediumArray, Simulation
1706Where Will the Ball FallMediumArray, Matrix, Simulation
1801Number of Orders in the BacklogMediumArray, Simulation, Heap (Priority Queue)
1806Minimum Number of Operations to Reinitialize a PermutationMediumArray, Math, Simulation
1823Find the Winner of the Circular GameMediumRecursion, Queue, Array +2
1860Incremental Memory LeakMediumMath, Simulation
1894Find the Student that Will Replace the ChalkMediumArray, Binary Search, Prefix Sum +1
1910Remove All Occurrences of a SubstringMediumStack, String, Simulation
1914Cyclically Rotating a GridMediumArray, Matrix, Simulation
2028Find Missing ObservationsMediumArray, Math, Simulation
2043Simple Bank SystemMediumDesign, Array, Hash Table +1
2075Decode the Slanted CiphertextMediumString, Simulation
2079Watering PlantsMediumArray, Simulation
2105Watering Plants IIMediumArray, Two Pointers, Simulation
2109Adding Spaces to a StringMediumArray, Two Pointers, String +1
2120Execution of All Suffix Instructions Staying in a GridMediumString, Simulation
2149Rearrange Array Elements by SignMediumArray, Two Pointers, Simulation
2161Partition Array According to Given PivotMediumArray, Two Pointers, Simulation
2177Find Three Consecutive Integers That Sum to a Given NumberMediumMath, Simulation
2181Merge Nodes in Between ZerosMediumLinked List, Simulation
2201Count Artifacts That Can Be ExtractedMediumArray, Hash Table, Simulation
2211Count Collisions on a RoadMediumStack, String, Simulation
2221Find Triangular Sum of an ArrayMediumArray, Math, Combinatorics +1
2257Count Unguarded Cells in the GridMediumArray, Matrix, Simulation
2295Replace Elements in an ArrayMediumArray, Hash Table, Simulation
2326Spiral Matrix IVMediumArray, Linked List, Matrix +1
2327Number of People Aware of a SecretMediumQueue, Dynamic Programming, Simulation
2352Equal Row and Column PairsMediumArray, Hash Table, Matrix +1
2365Task Scheduler IIMediumArray, Hash Table, Simulation
2380Time Needed to Rearrange a Binary StringMediumString, Dynamic Programming, Simulation
2390Removing Stars From a StringMediumStack, String, Simulation
2462Total Cost to Hire K WorkersMediumArray, Two Pointers, Simulation +1
2482Difference Between Ones and Zeros in Row and ColumnMediumArray, Matrix, Simulation
2502Design Memory AllocatorMediumDesign, Array, Hash Table +1
2507Smallest Value After Replacing With Sum of Prime FactorsMediumMath, Number Theory, Simulation
2593Find Score of an Array After Marking All ElementsMediumArray, Hash Table, Sorting +2
2596Check Knight Tour ConfigurationMediumDepth-First Search, Breadth-First Search, Array +2
2679Sum in a MatrixMediumArray, Matrix, Sorting +2
2766Relocate MarblesMediumArray, Hash Table, Sorting +1
2961Double Modular ExponentiationMediumArray, Math, Simulation
348Design Tic-Tac-ToePremiumMediumDesign, Array, Hash Table +2
353Design Snake GamePremiumMediumDesign, Queue, Array +2
544Output Contest MatchesPremiumMediumRecursion, String, Simulation
723Candy CrushPremiumMediumArray, Two Pointers, Matrix +1
755Pour WaterPremiumMediumArray, Simulation
1756Design Most Recently Used QueuePremiumMediumDesign, Array, Linked List +3
2061Number of Spaces Cleaning Robot CleanedPremiumMediumArray, Matrix, Simulation
2069Walking Robot Simulation IIMediumDesign, Simulation

Hard (10)

#ProblemDifficultyTopics
68Text JustificationHardArray, String, Simulation
749Contain VirusHardDepth-First Search, Breadth-First Search, Array +2
1606Find Servers That Handled Most Number of RequestsHardArray, Ordered Set, Simulation +1
2056Number of Valid Move Combinations On ChessboardHardArray, String, Backtracking +1
2296Design a Text EditorHardStack, Design, Linked List +3
2402Meeting Rooms IIIHardArray, Hash Table, Sorting +2
2532Time to Cross a BridgeHardArray, Simulation, Heap (Priority Queue)
2751Robot CollisionsHardStack, Array, Sorting +1
158Read N Characters Given read4 II - Call Multiple TimesPremiumHardArray, Interactive, Simulation
2534Time Taken to Cross the DoorPremiumHardQueue, Array, Simulation

When the Simulation problem arrives live

Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.