Math & Logic LeetCode Problems A collection of LeetCode problems solved using Math & Logic pattern techniques, explanations, and complexity analysis. Problems Easy # Problem Language Time Space Explanation 118 Pascal's Triangle JavaScript, PHP, Python O(n) O(1) Explanation 119 Pascal's Triangle II PHP O(n) O(1) Explanation 121 Best Time to Buy and Sell Stock JavaScript, PHP, Python O(n) O(1) Explanation 258 Add Digits PHP O(n) O(1) Explanation 448 Find All Numbers Disappeared in an Array TypeScript O(n) O(1) Explanation 482 License Key Formatting JavaScript, Python O(n) O(1) Explanation 485 Max Consecutive Ones TypeScript O(n) O(1) Explanation 796 Rotate String C++, JavaScript O(n) O(1) Explanation 812 Largest Triangle Area Python O(n) O(1) Explanation 836 Rectangle Overlap JavaScript O(n) O(1) Explanation 976 Largest Perimeter Triangle Python O(n) O(1) Explanation 1295 Find Numbers with Even Number of Digits Python O(n) O(1) Explanation 1431 Kids With the Greatest Number of Candies JavaScript, Python O(n) O(1) Explanation 1732 Find the Highest Altitude JavaScript, Kotlin, Python O(n) O(1) Explanation 1736 Latest Time by Replacing Hidden Digits C++ O(n) O(1) Explanation 1796 Second Largest Digit in a String C++ O(n) O(1) Explanation 1837 Sum of Digits in Base K C++ O(n) O(1) Explanation 1844 Replace All Digits with Characters C++ O(n) O(1) Explanation 1945 Sum of Digits of String After Convert C++ O(n) O(1) Explanation 1974 Minimum Time to Type Word Using Special Typewriter JavaScript O(n) O(1) Explanation 2073 Time Needed to Buy Tickets JavaScript O(n) O(1) Explanation 2160 Minimum Sum of Four Digit Number After Splitting Digits Python O(n) O(1) Explanation 2231 Largest Number After Digit Swaps by Parity JavaScript O(n) O(1) Explanation 2243 Calculate Digit Sum of a String Python O(n) O(1) Explanation 2259 Remove Digit From Number to Maximize Result Python O(n) O(1) Explanation 2549 Count Distinct Numbers on Board JavaScript O(n) O(1) Explanation 2553 Separate the Digits in an Array C++ O(n) O(1) Explanation 2558 Take Gifts From the Richest Pile Python O(n) O(1) Explanation 2566 Maximum Difference by Remapping a Digit Python O(n) O(1) Explanation 2582 Pass the Pillow JavaScript O(n) O(1) Explanation 2605 Form Smallest Number From Two Digit Arrays Python O(n) O(1) Explanation 2739 Total Distance Traveled JavaScript O(n) O(1) Explanation 2748 Number of Beautiful Pairs JavaScript O(n) O(1) Explanation 2873 Maximum Value of an Ordered Triplet I JavaScript O(n) O(1) Explanation 2928 Distribute Candies Among Children I JavaScript O(n) O(1) Explanation 3174 Clear Digits Python O(n) O(1) Explanation 3300 Minimum Element After Replacement With Digit Sum C++ O(n) O(1) Explanation 3354 Make Array Elements Equal to Zero JavaScript O(n) O(1) Explanation 3411 Maximum Subarray With Equal Products JavaScript O(n) O(1) Explanation 3461 Check If Digits Are Equal in String After Operations I JavaScript O(n) O(1) Explanation 3483 Unique 3-Digit Even Numbers JavaScript O(n) O(1) Explanation 3536 Maximum Product of Two Digits Erlang O(n) O(1) Explanation 3622 Check Divisibility by Digit Sum and Product C, Python O(n) O(1) Explanation 4000 Largest Integer With Given Digit Sum JavaScript O(n) O(1) Explanation Medium # Problem Language Time Space Explanation 48 Rotate Image C++, JavaScript O(n²) O(1) Explanation 55 Jump Game JavaScript, Python O(n) O(1) Explanation 128 Longest Consecutive Sequence JavaScript, Python O(n) O(1) Explanation 223 Rectangle Area Python O(n) O(1) Explanation 229 Majority Element II JavaScript O(n) O(1) Explanation 289 Game of Life JavaScript O(n) O(1) Explanation 319 Bulb Switcher Python O(n) O(1) Explanation 357 Count Numbers with Unique Digits Python O(n) O(1) Explanation 365 Water and Jug Problem Python O(n) O(1) Explanation 400 Nth Digit Python O(n) O(1) Explanation 497 Random Point in Non-overlapping Rectangles Python O(n) O(1) Explanation 714 Best Time to Buy and Sell Stock with Transaction Fee JavaScript O(n) O(1) Explanation 738 Monotone Increasing Digits Python O(n) O(1) Explanation 807 Max Increase to Keep City Skyline JavaScript O(n) O(1) Explanation 858 Mirror Reflection Python O(n) O(1) Explanation 909 Snakes and Ladders JavaScript O(n) O(1) Explanation 949 Largest Time for Given Digits Python O(n) O(1) Explanation 1006 Clumsy Factorial JavaScript O(n) O(1) Explanation 1041 Robot Bounded In Circle Python O(n) O(1) Explanation 1093 Statistics from a Large Sample JavaScript O(n) O(1) Explanation 1201 Ugly Number III Python O(n) O(1) Explanation 1344 Angle Between Hands of a Clock Java O(n) O(1) Explanation 1362 Closest Divisors Python O(n) O(1) Explanation 1401 Circle and Rectangle Overlapping JavaScript O(n) O(1) Explanation 1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit JavaScript O(n) O(1) Explanation 1447 Simplified Fractions Python O(n) O(1) Explanation 1476 Subrectangle Queries Python O(n) O(1) Explanation 1615 Maximal Network Rank JavaScript O(n) O(1) Explanation 2145 Count the Hidden Sequences JavaScript O(n) O(1) Explanation 2241 Design an ATM Machine JavaScript O(n) O(1) Explanation 2249 Count Lattice Points Inside a Circle Python O(n) O(1) Explanation 2310 Sum of Numbers With Units Digit K Python O(n) O(1) Explanation 2327 Number of People Aware of a Secret JavaScript O(n) O(1) Explanation 2342 Max Sum of a Pair With Equal Sum of Digits JavaScript O(n) O(1) Explanation 2447 Number of Subarrays With GCD Equal to K Python O(n) O(1) Explanation 2470 Number of Subarrays With LCM Equal to K Python O(n) O(1) Explanation 2513 Minimize the Maximum of Two Arrays Python O(n) O(1) Explanation 2545 Sort the Students by Their Kth Score Python O(n) O(1) Explanation 2607 Make K-Subarray Sums Equal Python O(n) O(1) Explanation 2637 Promise Time Limit TypeScript O(n) O(1) Explanation 2654 Minimum Number of Operations to Make All Array Elements Equal to 1 Python O(n) O(1) Explanation 3012 Minimize Length of Array Using Operations JavaScript O(n) O(1) Explanation 3111 Minimum Rectangles to Cover Points JavaScript O(n) O(1) Explanation 3115 Maximum Prime Difference Kotlin O(n) O(1) Explanation 3224 Minimum Array Changes to Make Differences Equal JavaScript O(n) O(1) Explanation 3341 Find Minimum Time to Reach Last Room I JavaScript O(n) O(1) Explanation 3342 Find Minimum Time to Reach Last Room II JavaScript O(n) O(1) Explanation 3381 Maximum Subarray Sum With Length Divisible by K JavaScript O(n) O(1) Explanation 3443 Maximum Manhattan Distance After K Changes JavaScript O(n) O(1) Explanation 3473 Sum of K Subarrays With Length at Least M JavaScript O(n) O(1) Explanation 3604 Minimum Time to Reach Destination in Directed Graph JavaScript O(n) O(1) Explanation 3618 Split Array by Prime Indices JavaScript O(n) O(1) Explanation 3723 Maximize Sum of Squares of Digits Python O(n) O(1) Explanation 3819 Rotate Non Negative Elements Python O(n) O(1) Explanation 3899 Angles of a Triangle Python O(n) O(1) Explanation 3968 Maximum Manhattan Distance After All Moves JavaScript O(n) O(1) Explanation 3969 Valid Subarrays With Matching Sum Digits I Python O(n) O(1) Explanation 4022 K-th Digit in Infinite String Python O(n) O(1) Explanation Hard # Problem Language Time Space Explanation 123 Best Time to Buy and Sell Stock III JavaScript O(n) O(1) Explanation 391 Perfect Rectangle Python O(n) O(1) Explanation 850 Rectangle Area II Python O(n) O(1) Explanation 862 Shortest Subarray with Sum at Least K JavaScript O(n) O(1) Explanation 1250 Check If It Is a Good Array Python O(n) O(1) Explanation 1453 Maximum Number of Darts Inside of a Circular Dartboard Python O(n) O(1) Explanation 1515 Best Position for a Service Centre Python O(n) O(1) Explanation 1610 Maximum Number of Visible Points Python O(n) O(1) Explanation 2071 Maximum Number of Tasks You Can Assign JavaScript O(n) O(1) Explanation 2398 Maximum Number of Robots Within Budget JavaScript O(n) O(1) Explanation 2444 Count Subarrays With Fixed Bounds JavaScript O(n) O(1) Explanation 2543 Check if Point Is Reachable Python O(n) O(1) Explanation 3154 Find Number of Ways to Reach the K-th Stair JavaScript O(n) O(1) Explanation 3317 Find the Number of Possible Ways for an Event JavaScript O(n) O(1) Explanation 3378 Count Connected Components in LCM Graph Python O(n) O(1) Explanation 3463 Check If Digits Are Equal in String After Operations II JavaScript O(n) O(1) Explanation