Code with Carter
Code with Carter
  • 198
  • 126 603
2909. Minimum Sum of Mountain Triplets II - LeetCode Python tutorial
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "2909. Minimum Sum of Mountain Triplets II".
Question: leetcode.com/problems/minimum-sum-of-mountain-triplets-ii
If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily!
#leetcode #python #python3 #tutorial #coding #programming #leetcodedailychallenge #dailychallenge
Переглядів: 317

Відео

2908. Minimum Sum of Mountain Triplets I - LeetCode Python tutorial
Переглядів 34811 місяців тому
Today I solve and explain very quickly an easy level difficulty leetcode algorithm using Python3 called "2908. Minimum Sum of Mountain Triplets i". Question: leetcode.com/problems/minimum-sum-of-mountain-triplets-i If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily! #leetcode #python #python3 #tutorial #coding #programming #leetcodeda...
119. Pascal's Triangle II - LeetCode Python tutorial
Переглядів 21511 місяців тому
Today I solve and explain very quickly an easy level difficulty leetcode algorithm using Python3 called "119. Pascal's Triangle II". I go over two different mathematical formulas to solve this using either a recursive or iterative approach. Question: leetcode.com/problems/pascals-triangle-ii If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problem...
2875. Minimum Size Subarray in Infinite Array - LeetCode Python tutorial
Переглядів 375Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "2875. Minimum Size Subarray in Infinite Array". Question: leetcode.com/problems/minimum-size-subarray-in-infinite-array If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily! #leetcode #python #python3 #tutorial #coding #programming ...
LeetCode 2038. Remove Colored Pieces if Both Neighbors are the Same Color - Python Solution
Переглядів 152Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "2038. Remove Colored Pieces if Both Neighbors are the Same Color". I go over how to solve this question in O(N) time & O(1) space by using a "Greedy" approach without having to actually play the entire game. Question: leetcode.com/problems/remove-colored-pieces-if-both-neighbors-are-the-sam...
456. 132 Pattern - LeetCode Python tutorial
Переглядів 597Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "456. 132 Pattern". I go over how to solve this question in O(N) time & O(N) space while iterating through the array backwards using a monotonic decreasing stack! Question: leetcode.com/problems/monotonic-array If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python...
Leetcode 896. Monotonic Array - Python tutorial
Переглядів 137Рік тому
Today I solve and explain very quickly an easy level difficulty leetcode algorithm using Python3 called "896. Monotonic Array". I go over how to solve this question in O(N) time & constant space while iterating through the array just once! Question: leetcode.com/problems/monotonic-array If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems dai...
Leetcode 2393. Count Strictly Increasing Subarrays - Python tutorial
Переглядів 152Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "2393. Count Strictly Increasing Subarrays". I go over two possible approaches. One using a monotonic stack the other using the "kadane-ish" pattern. Essentially allowing us to go from O(N) space complexity to O(1)! Question: leetcode.com/problems/count-strictly-increasing-subarrays If you f...
550. Game Play Analysis IV - LeetCode SQL Question
Переглядів 456Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode database query problem using MySQL called "550. Game Play Analysis IV". This is a popular data engineering interview question that makes use of three different queries. Question: leetcode.com/problems/game-play-analysis-iv If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Pro...
316. Remove Duplicate Letters - Google Interview Question
Переглядів 210Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "316. Remove Duplicate Letters". This is a popular interview question from Google using the Stack Data Structure. Question: leetcode.com/problems/remove-duplicate-letters If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily! #leetcod...
877. Stone Game - Cisco Interview Question
Переглядів 125Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "877. Stone Game". This is a popular interview question from Cisco using the minimax algorithm. Question: leetcode.com/problems/stone-game If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily! #leetcode #python #python3 #tutorial #co...
1658. Minimum Operations to Reduce X to Zero - Apple Interview Question
Переглядів 175Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "1658. Minimum Operations to Reduce X to Zero". This is a popular interview question using the Sliding Window Pattern. Question: leetcode.com/problems/minimum-operations-to-reduce-x-to-zero If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Probl...
Leetcode 287. Find the Duplicate Number - Microsoft Interview Question
Переглядів 973Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "287. Find the Duplicate Number". This is a popular Microsoft Interview problem using Floyd's Cycle Detection Algorithm. Question: leetcode.com/problems/find-the-duplicate-number If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily! ...
1570. Dot Product of Two Sparse Vectors - Facebook Interview Question
Переглядів 2,4 тис.Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "1570. Dot Product of Two Sparse Vectors". This is a popular Facebook Interview problem using a hashmap. Question: leetcode.com/problems/dot-product-of-two-sparse-vectors/ If you found this helpful Like and Subscribe! I solve LeetCode Algorithms (Python/ Java) and SQL Problems daily! #leetco...
[Tesla Interview] Leetcode 1239. Maximum Length of a Concatenated String with Unique Characters
Переглядів 489Рік тому
Today I solve and explain very quickly a medium level difficulty leetcode algorithm using Python3 called "1239. Maximum Length of a Concatenated String with Unique Characters". This is a popular Tesla Interview problem using the backtracking pattern. Question: leetcode.com/problems/maximum-length-of-a-concatenated-string-with-unique-characters If you found this helpful Like and Subscribe! I sol...
LeetCode 1282. Group the People Given the Group Size They Belong To - Apple Interview Question
Переглядів 508Рік тому
LeetCode 1282. Group the People Given the Group Size They Belong To - Apple Interview Question
LeetCode 2519. Count the Number of K-Big Indices - Amazon Interview Question
Переглядів 1,2 тис.Рік тому
LeetCode 2519. Count the Number of K-Big Indices - Amazon Interview Question
LeetCode 358. Rearrange String k Distance Apart - Google Interview Question
Переглядів 518Рік тому
LeetCode 358. Rearrange String k Distance Apart - Google Interview Question
LeetCode 725. Split Linked List in Parts - Amazon Interview Question
Переглядів 145Рік тому
LeetCode 725. Split Linked List in Parts - Amazon Interview Question
LeetCode 138. Copy List with Random Pointer [IN 3 MINUTES]
Переглядів 148Рік тому
LeetCode 138. Copy List with Random Pointer [IN 3 MINUTES]
6 GRAPH PROBLEMS SOLVED | LeetCode Grind 2023 | Blind 75 List
Переглядів 1 тис.Рік тому
6 GRAPH PROBLEMS SOLVED | LeetCode Grind 2023 | Blind 75 List
11 TREE PROBLEMS SOLVED | LeetCode Grind 2023 | Blind 75 List
Переглядів 713Рік тому
11 TREE PROBLEMS SOLVED | LeetCode Grind 2023 | Blind 75 List
SOLVING ALL Linked List | Blind75 LeetCode Problems
Переглядів 679Рік тому
SOLVING ALL Linked List | Blind75 LeetCode Problems
Solving All Blind75 Binary Search Pattern LeetCode Problems
Переглядів 387Рік тому
Solving All Blind75 Binary Search Pattern LeetCode Problems
SOLVING ALL Sliding Window [Blind75 List] | LeetCode Problems
Переглядів 334Рік тому
SOLVING ALL Sliding Window [Blind75 List] | LeetCode Problems
20. Valid Parentheses - Stack Pattern [Blind75 List]
Переглядів 211Рік тому
20. Valid Parentheses - Stack Pattern [Blind75 List]
Solving All Two Pointer Pattern | Blind75 LeetCode Problems
Переглядів 1,8 тис.Рік тому
Solving All Two Pointer Pattern | Blind75 LeetCode Problems
SOLVING ALL Arrays & Hashmap | Blind75 LeetCode Problems
Переглядів 6 тис.Рік тому
SOLVING ALL Arrays & Hashmap | Blind75 LeetCode Problems
Consistent Hashing Explained - System Design Fundamentals
Переглядів 663Рік тому
Consistent Hashing Explained - System Design Fundamentals
2369. Check if There is a Valid Partition For The Array - Leetcode Python Solution
Переглядів 54Рік тому
2369. Check if There is a Valid Partition For The Array - Leetcode Python Solution

КОМЕНТАРІ

  • @santiagogomezramirez1627
    @santiagogomezramirez1627 День тому

    clear and creative, respect +

  • @3227998
    @3227998 2 дні тому

    why is the bottom-up approach called a "true DP"? Is it because you are starting from smaller problem and building it up to the end result? If so, doesn't top-down, in principal, do the same thing by reaching the base case then unwinding the recursive stack from there?

    • @codewithcarter
      @codewithcarter 2 дні тому

      @@3227998 IMO I think it’s because when you do bottom up you have a chance (not guaranteed) that you can get space optimization of O(1) or say O(LOG(N)). However, when you’re doing too down you always have the recursive stack or some kind of memorization which attributes to added space. So in other words often the bottom up approach is preferable as it can lead to space optimization.

  • @ahjiba
    @ahjiba 2 дні тому

    Crazy clean solution - would love to see the recursive proof behind this

  • @thomshetland
    @thomshetland 5 днів тому

    I mean, wont it grab the 8 since you are using num % 10, and not 3? And when you divide with 10, it wont take away 3, it will take away 8:)

  • @nafis_rk
    @nafis_rk 7 днів тому

    This one was a fun problem!

  • @nbktechworld
    @nbktechworld 12 днів тому

    The problem becomes clear once you realize computing the actual product is irrelevant.

  • @mixone6168
    @mixone6168 14 днів тому

    This is the 3rd video I watched. Simplest explanation, I think.

  • @adennis200
    @adennis200 15 днів тому

    Hmm, I kinda miss the point where you explain why the reset actually works.. Does it require to have a certain amount of items or does the cycle needs to have a certain length? Cause I read that it doesnt matter where the pointers meet initially, resetting will always make sure you get the start. But thats complete nonsense right? Cause if i have a list 1-2-3-4-5-6 and a cycle 456 with 6 pointing to 4, thats mathematically not possible, right?

  • @artimes5542
    @artimes5542 16 днів тому

    I came here from Cracking the Interview because I was stumped by problem 4.3 which is this same problem, nice explanation!

  • @chandanpatra1053
    @chandanpatra1053 18 днів тому

    Please provide the create & insert statement for every question you practice on leetcode. Provide questions in your github account.

  • @SamuelEvans1991
    @SamuelEvans1991 19 днів тому

    Thanks, you really simplified the problem

  • @lukaszm9234
    @lukaszm9234 Місяць тому

    Can't we deduce the whitespace_count by subtracting charr_array.length - actual_length?

  • @vileni1
    @vileni1 Місяць тому

    Sorry But what is the point of leetcode or exercising if you still use some library which abstract the solution?

    • @codewithcarter
      @codewithcarter Місяць тому

      @@vileni1 collections is a pretty famous library so using Counter is fairly well documented. Nonetheless, using a hash map works fine is just an extra line of code or two.

  • @firezdog
    @firezdog Місяць тому

    it seemed like a monotonic stack worked from right to left -- was really hoping it would also work from left to right

  • @SHUBHAMJHA-o3g
    @SHUBHAMJHA-o3g Місяць тому

    I cant thank you enough I was literally looking for someone to explain why we are using inclusion and exclusion!!!!!!! damn. I was using the initial intuition approach that you should was wrong and it was counting multiple times. And i was tryna use sets but that would be real inefficient. I still might have to understand it more, to really hit the spot but It was a really nice ice breaker. Basically I was thinking to prove how the code prevents {1,2,3} and {3,2,1} !

  • @bidhanry9740
    @bidhanry9740 Місяць тому

    Hi, I am a beginner in sql, just started learning and side by side solving problems, I understood till half I kept myself stick to the concepts you were delivering, then at some point I lost, is it normal or it means I still need to study sql a lot?

  • @CPCODE14
    @CPCODE14 Місяць тому

    Hello....can you please provide us the all pattern playlist....like two pointers, backtracking, dp , graphs , trees , sliding window and so on ...

  • @ronihossain7428
    @ronihossain7428 Місяць тому

    Very good solution.

  • @itsnotxueying
    @itsnotxueying Місяць тому

    Please finish all blind 75 plsssss! Your video is so well explained! It's the best resource to learn using python to leetcode

  • @ΑγγελοςΑσημακοπουλος-ζ1η

    My solution goes like that: for key in hash_map: key_end = key start = 0 While key_end <= len(hash_map[key]): res2 = [] for i in range(start_end, key_end): res_2.append(hash_map[key][i]) start = key_end key_end += key res.append(res2)

  • @nrk07
    @nrk07 Місяць тому

    Hey Carter, Thanks

  • @itsnotxueying
    @itsnotxueying Місяць тому

    Love the blind 75 collection videos, I do leetcode a lot faster when I do it with you!

  • @DharshanNadar0
    @DharshanNadar0 Місяць тому

    Thanks Man . Best solution video on yt by far for this question. 😄

  • @SAURABHKUMAR-uk5gg
    @SAURABHKUMAR-uk5gg Місяць тому

    FYI - the code used is not directed towards the most efficient time and space complexity, it's more so to understand the data structures in Python and the methods/functions applied on top of it. If you really want the time space complexity, refer to the original NeetCode videos. Thank you Carter, the videos are a good way of refresher for DE interviews

  • @Martinnnnnn-e5s
    @Martinnnnnn-e5s Місяць тому

    you made this problem look so easy 😲

  • @BaoNguyen-d8u
    @BaoNguyen-d8u Місяць тому

    thank you kind sir

  • @osamakhidr7559
    @osamakhidr7559 2 місяці тому

    thank you from Egypt you are great

  • @AishwaryaAishwarya-e4l
    @AishwaryaAishwarya-e4l 2 місяці тому

    wow!!!!!!!!!!! thankyouu!!!

  • @SMMahediHasan-BANGLADESH
    @SMMahediHasan-BANGLADESH 2 місяці тому

    Good

  • @viper440
    @viper440 2 місяці тому

    what tool do you use to write on the screen? I could really use that tool to help me organize my thoughts

  • @lbigolEdawgl
    @lbigolEdawgl 2 місяці тому

    This was very helpful. The way that you step through and explain why certain things were done really helps to understand the bigger picture. Keep it up!!

  • @bardandhakal7300
    @bardandhakal7300 2 місяці тому

    the edge case was very confusing. I did not get any of it

  • @tindo0038
    @tindo0038 2 місяці тому

    What is the intuition behind starting at node after head for the hare ptr in has_cycle?

  • @algopenne
    @algopenne 2 місяці тому

    great video! what program do you use to write on the screen?

  • @shantipriya370
    @shantipriya370 2 місяці тому

    wonderful.. thanks

  • @dwk1987
    @dwk1987 2 місяці тому

    This solution is so much better than any others

  • @dharanyuvi6951
    @dharanyuvi6951 2 місяці тому

    Hey can this be written in tabulation. I mean in the same way that you wrote the memoization? Because i tried but couldn't able to make it

  • @dalespiteri
    @dalespiteri 2 місяці тому

    The solution to the first problem doesn't work for me, but I think they've updated Neetcode's test for this question. In cases where the array has _not_ been rotated, we never achieve an answer here since it will continue to search the right side of the array in the default else statement, and we'll never find a situation where nums[m - 1] is greater than nums[m]. I needed to add a condition to return nums[l] when nums[m] is greater than or equal to nums[l], and less than nums[r]. This situation should always mean that the array between left and right are sorted, meaning the left pointer is pointing at the first index of sorted array. There is also an issue when the array has a length of one. That's easily solvable with an if statement before starting to return the one item. Last issue was with array of length 2. I needed to update my while statement to read: while (l <= r). In the provided solution here, in a two item array that's been rotated to [2, 1], it would correctly realize the dip is on the right side, move the left point at index 1, and keep the right pointer at index 1, making them equal and then exiting the loop, ultimately returning nothing. Adding the less than _or equal_ condition to the while loop makes sure it runs that last loop and checks the number you've found when you've drilled down to the last possible index. Maybe I messed something up, because I am working in JS, and not Python, but I don't think this solution as written would work in the circumstances that provide errors on Neetcode. The hangups were [4,5,6,7], [1], and [2,1] .... re-reading it, I think I made a mistake by not including the final return nums[l]... I think that alleviates all the issues in those 3 arrays. I'll leave the comment in case someone makes the same mistake.

  • @lavanya_m01
    @lavanya_m01 2 місяці тому

    Brilliant! I guess you used UnionBySize. Anyway, didn't think of tweaking the UnionFind by introducing a new variable num_comb. Thanks a lot! subbed :)

  • @gxyxy1012
    @gxyxy1012 2 місяці тому

    it makes sense, but how do I intuitively know to -6 or -29 when working with current index?

  • @Siyibuyisel_eKasi
    @Siyibuyisel_eKasi 2 місяці тому

    Great explanation bro, much easier to understand compared to other videos

  • @mohammad-javadd.b.5224
    @mohammad-javadd.b.5224 2 місяці тому

    for 242. Valid Anagram if we are allowed to use Counter, why not just ` return Counter(s)==Counter(t)'

  • @анекдотыч-й9ж
    @анекдотыч-й9ж 3 місяці тому

    what about time complexity? Seems like window function solution is O(n) and join solution is O(n^2) in case if nested loop is used, am i wrong?

  • @garvitakalra3324
    @garvitakalra3324 3 місяці тому

    And if the list has no intersecting node, what is the exit condition?

  • @AI-ew1rj
    @AI-ew1rj 3 місяці тому

    How does the row number approach work to group rows into buckets? I saw how you did it but don’t understand the intuition

  • @abhaypandey2668
    @abhaypandey2668 3 місяці тому

    what if the rows are unsorted?

  • @jst8922
    @jst8922 3 місяці тому

    # Here's an optimized version of the code: # leetcode runtime reduced from 44 ms to 26 ms class Solution: def uniquePaths(self, m: int, n: int) -> int: # Use a 1D array to store intermediate results dp = [1] * n for i in range(1, m): for j in range(1, n): dp[j] += dp[j-1] return dp[-1] This optimized version has the following advantages: 1. It uses a bottom-up approach, eliminating the overhead of recursive function calls. 2. It uses a 1D array instead of a 2D array, reducing space complexity from O(m*n) to O(n). 3. It iterates through the grid only once, making it more efficient for larger inputs. The time complexity remains O(m*n), but the constant factors are reduced, making it faster in practice. The space complexity is improved to O(n). This solution should be faster and more memory-efficient than the original recursive approach, especially for larger grid sizes. --- same code with comments: class Solution: def uniquePaths(self, m: int, n: int) -> int: # Initialize a 1D array with n elements, all set to 1 # This represents the first row of the grid, where there's only one way to reach each cell dp = [1] * n # Iterate through the rows of the grid (starting from the second row) for i in range(1, m): # Iterate through the columns of the grid (starting from the second column) for j in range(1, n): # Update the current cell by adding the number of paths from the cell above (dp[j]) # and the cell to the left (dp[j-1]) dp[j] += dp[j-1] # Return the last element of the dp array, which represents the bottom-right cell of the grid return dp[-1] Here's a more detailed explanation of the algorithm: 1. We initialize a 1D array `dp` with `n` elements, all set to 1. This represents the first row of the grid, where there's only one way to reach each cell (moving right). 2. We then iterate through the grid row by row, starting from the second row (index 1). 3. For each row, we iterate through the columns, starting from the second column (index 1). 4. For each cell, we update its value by adding the number of paths from the cell above (which is already stored in `dp[j]`) and the cell to the left (which is `dp[j-1]`). 5. After processing all cells, the last element of the `dp` array (`dp[-1]`) contains the total number of unique paths to reach the bottom-right corner of the grid. 6. We return this value as the final result. This approach efficiently calculates the number of unique paths by using dynamic programming with optimized space complexity, storing only one row of intermediate results at a time.

    • @jst8922
      @jst8922 3 місяці тому

      btw, "@cache" decorator requires import the cache decorator from the functools module at the beginning of code, like this: from functools import cache class Solution: def uniquePaths(self, m: int, n: int) -> int: @cache def dp(r, c): #base case if (r, c) == (m -1 , n - 1): return 1 elif r == m or c == n: #we stepped outside the bounds return 0 return dp(r + 1, c) + dp(r, c + 1) return dp(0, 0) --- If one is using a Python version earlier than 3.9, use lru_cache instead, which provides similar functionality: example from functools import lru_cache class Solution: def uniquePaths(self, m: int, n: int) -> int: @lru_cache(None) def dp(r, c): # ... rest of the code remains the same

  • @roshninv
    @roshninv 3 місяці тому

    thanks Carter, that was helpful !

  • @23cash86
    @23cash86 3 місяці тому

    Clear...

  • @maheshguntaka8000
    @maheshguntaka8000 3 місяці тому

    Hello, can you also explain the time complexity and space complexity? As I am having a google interview and the time I have 2 and half weeks. I have 0% knowledge on dsa. It would be a great help. I know I am not able to crack it but atleast I don't want to give up.