Skip to content

Latest commit

 

History

History
191 lines (182 loc) · 38.7 KB

math-logic.md

File metadata and controls

191 lines (182 loc) · 38.7 KB

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
2264 Largest 3-Same-Digit Number in String Python O(n) O(1) Explanation
2441 Largest Positive Integer That Exists With Its Negative JavaScript O(n) O(1) Explanation
2520 Count the Digits That Divide a Number Python O(n) O(1) Explanation
2535 Difference Between Element Sum and Digit Sum of an Array Python O(n) O(1) Explanation
2544 Alternating Digit Sum 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
2894 Divisible and Non-divisible Sums Difference JavaScript O(n) O(1) Explanation
2908 Minimum Sum of Mountain Triplets I JavaScript O(n) O(1) Explanation
2928 Distribute Candies Among Children I JavaScript O(n) O(1) Explanation
3000 Maximum Area of Longest Diagonal Rectangle JavaScript O(n) O(1) Explanation
3024 Type of Triangle JavaScript O(n) O(1) Explanation
3079 Find the Sum of Encrypted Integers JavaScript O(n) O(1) Explanation
3099 Harshad Number JavaScript O(n) O(1) Explanation
3110 Score of a String JavaScript O(n) O(1) Explanation
3174 Clear Digits Python O(n) O(1) Explanation
3232 Find if Digit Game Can Be Won JavaScript O(n) O(1) Explanation
3289 The Two Sneaky Numbers of Digitville JavaScript 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
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
3487 Maximum Unique Subarray Sum After Deletion 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
3774 Absolute Difference Between Maximum and Minimum K Elements JavaScript O(n) O(1) Explanation
3908 Valid Digit Number Python O(n) O(1) Explanation
3931 Check Adjacent Digit Differences Python O(n) O(1) Explanation
3982 Sum of Integers with Maximum Digit Range Python O(n) O(1) Explanation
4000 Largest Integer With Given Digit Sum JavaScript O(n) O(1) Explanation
4061 Minimum Queen Moves to Reach Target JavaScript O(n) O(1) Explanation
4070 Minimum Rotations to Dial a Number I 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
1921 Eliminate Maximum Number of Monsters 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
2274 Maximum Consecutive Floors Without Special Floors JavaScript 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
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
2849 Determine if a Cell Is Reachable at a Given Time JavaScript O(n) O(1) Explanation
2918 Minimum Equal Sum of Two Arrays After Replacing Zeros JavaScript O(n) O(1) Explanation
2957 Remove Adjacent Almost-Equal Characters JavaScript O(n) O(1) Explanation
3012 Minimize Length of Array Using Operations JavaScript O(n) O(1) Explanation
3021 Alice and Bob Playing Flower Game JavaScript O(n) O(1) Explanation
3075 Maximize Happiness of Selected Children JavaScript O(n) O(1) Explanation
3106 Lexicographically Smallest String After Operations With Constraint JavaScript O(n) O(1) Explanation
3107 Minimum Operations to Make Median of Array Equal to K JavaScript O(n) O(1) Explanation
3115 Maximum Prime Difference Kotlin O(n) O(1) Explanation
3169 Count Days Without Meetings JavaScript O(n) O(1) Explanation
3196 Maximize Total Cost of Alternating Subarrays JavaScript O(n) O(1) Explanation
3207 Maximum Points After Enemy Battles JavaScript O(n) O(1) Explanation
3224 Minimum Array Changes to Make Differences Equal JavaScript O(n) O(1) Explanation
3282 Reach End of Array With Max Score 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
3397 Maximum Number of Distinct Elements After Operations JavaScript O(n) O(1) Explanation
3424 Minimum Cost to Make Arrays Identical 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
3587 Minimum Adjacent Swaps to Alternate Parity 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
3675 Minimum Operations to Transform String JavaScript O(n) O(1) Explanation
3723 Maximize Sum of Squares of Digits Python O(n) O(1) Explanation
3732 Maximum Product of Three Elements After One Replacement JavaScript O(n) O(1) Explanation
3780 Maximum Sum of Three Numbers Divisible by Three JavaScript O(n) O(1) Explanation
3819 Rotate Non Negative Elements Python O(n) O(1) Explanation
3895 Count Digit Appearances 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
3974 Maximum Total Sum of K Selected Elements JavaScript O(n) O(1) Explanation
3993 Maximum Value of an Alternating Sequence JavaScript O(n) O(1) Explanation
4014 Minimum Total Price After Applying Discounts JavaScript O(n) O(1) Explanation
4022 K-th Digit in Infinite String Python O(n) O(1) Explanation
4025 Minimize the Maximum Waiting Time at Synchronized Traffic Lights JavaScript O(n) O(1) Explanation
4026 Maximum Gap Between Stations JavaScript O(n) O(1) Explanation
4034 Minimum Bishop Moves to Reach Target JavaScript O(n) O(1) Explanation
4071 Minimum Rotations to Dial a Number II JavaScript O(n) O(1) Explanation
4072 Maximum Alternating Subarray Sum With One Deletion JavaScript O(n) O(1) Explanation
4075 Longest Resilient Subarray I JavaScript O(n) O(1) Explanation
4076 Longest Resilient Subarray II JavaScript O(n) O(1) Explanation
4093 Maximize Sum After At Most K Digit Rearrangements 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
1012 Numbers With Repeated Digits Python 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
3273 Minimum Amount of Damage Dealt to Bob 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
3448 Count Substrings Divisible By Last Digit Python O(n) O(1) Explanation
3463 Check If Digits Are Equal in String After Operations II JavaScript O(n) O(1) Explanation