![LetsCode](/img/default-banner.jpg)
- 698
- 35 694
LetsCode
Registrace 15. 02. 2021
Leetcode on live, I use python to solve leetcode problems.
2024 target!
1 Aiming to finish uploading 1000 leetcode problems videos.
2 Reach 1000 subscribers.
3 Reach 100, 000 views.
2024 target!
1 Aiming to finish uploading 1000 leetcode problems videos.
2 Reach 1000 subscribers.
3 Reach 100, 000 views.
Video
Leetcode 1472. Design Browser History (stack and queue)
zhlédnutí 26Před 12 hodinami
1472. Design Browser History
2390. Removing Stars From a String (stack)
zhlédnutí 15Před 12 hodinami
2390. Removing Stars From a String
Leetcode 844. Backspace String Compare (two pointers)
zhlédnutí 8Před 14 hodinami
844. Backspace String Compare
Leetcode 844. Backspace String Compare (stack)
zhlédnutí 2Před 16 hodinami
844. Backspace String Compare
Leetcode 1441. Build an Array With Stack Operations (2 pointers)
zhlédnutí 12Před 16 hodinami
1441. Build an Array With Stack Operations
Leetcode 56. Merge Intervals (greedy and sweep line)
zhlédnutí 25Před 14 dny
Leetcode 56. Merge Intervals (greedy and sweep line)
Leetcode 1854. Maximum Population Year (difference array)
zhlédnutí 12Před 21 dnem
Leetcode 1854. Maximum Population Year (difference array)
Leetcode 1893. Check if All the Integers in a Range Are Covered (difference array)
zhlédnutí 19Před 21 dnem
Leetcode 1893. Check if All the Integers in a Range Are Covered (difference array)
Leetcode 2848. Points That Intersect With Cars (difference array)
zhlédnutí 10Před 21 dnem
Leetcode 2848. Points That Intersect With Cars (difference array)
Leetcode 1094. Car Pooling (difference array)
zhlédnutí 16Před 21 dnem
Leetcode 1094. Car Pooling (difference array)
Leetcode 3148. Maximum Difference Score in a Grid (2d prefix sum)
zhlédnutí 7Před 21 dnem
Leetcode 3148. Maximum Difference Score in a Grid (2d prefix sum)
Leetcode 1738. Find Kth Largest XOR Coordinate Value (2d prefix sum)
zhlédnutí 16Před 21 dnem
Leetcode 1738. Find Kth Largest XOR Coordinate Value (2d prefix sum)
Leetcode 1524. Number of Sub-arrays With Odd Sum (bfs)
zhlédnutí 8Před 21 dnem
Leetcode 1524. Number of Sub-arrays With Odd Sum (bfs)
Leetcode 930. Binary Subarrays With Sum (prefix + hash)
zhlédnutí 9Před 21 dnem
Leetcode 930. Binary Subarrays With Sum (prefix hash)
Leetcode 1744. Can You Eat Your Favorite Candy on Your Favorite Day? (prefix sum)
zhlédnutí 12Před 21 dnem
Leetcode 1744. Can You Eat Your Favorite Candy on Your Favorite Day? (prefix sum)
Leetcode 2438. Range Product Queries of Powers (prefix sum)
zhlédnutí 5Před 21 dnem
Leetcode 2438. Range Product Queries of Powers (prefix sum)
Leetcode 3152. Special Array II (prefix sum)
zhlédnutí 7Před 21 dnem
Leetcode 3152. Special Array II (prefix sum)
Leetcode 2389. Longest Subsequence With Limited Sum (prefix sum)
zhlédnutí 9Před 21 dnem
Leetcode 2389. Longest Subsequence With Limited Sum (prefix sum)
Leetcode 2613. Beautiful Pairs (computational geometry and divide and conquer)
zhlédnutí 5Před 21 dnem
Leetcode 2613. Beautiful Pairs (computational geometry and divide and conquer)
Leetcode 2342. Max Sum of a Pair With Equal Sum of Digits (Two sum)
zhlédnutí 7Před 21 dnem
Leetcode 2342. Max Sum of a Pair With Equal Sum of Digits (Two sum)
Leetcode 2748. Number of Beautiful Pairs (two sum)
zhlédnutí 6Před 21 dnem
Leetcode 2748. Number of Beautiful Pairs (two sum)
Leetcode 2815. Max Pair Sum in an Array (two sum)
zhlédnutí 6Před 21 dnem
Leetcode 2815. Max Pair Sum in an Array (two sum)
Leetcode 2741. Special Permutations (bit dp)
zhlédnutí 2Před 28 dny
Leetcode 2741. Special Permutations (bit dp)
Leetcode 526. Beautiful Arrangement (bit dp)
zhlédnutí 12Před 28 dny
Leetcode 526. Beautiful Arrangement (bit dp)
Leetcode 1201. Ugly Number III (binary search answer)
zhlédnutí 12Před 28 dny
Leetcode 1201. Ugly Number III (binary search answer)
Leetcode 878. Nth Magical Number (binary search answer)
zhlédnutí 11Před 28 dny
Leetcode 878. Nth Magical Number (binary search answer)
Leetcode 2371. Minimize Maximum Value in a Grid (greedy)
zhlédnutí 5Před měsícem
Leetcode 2371. Minimize Maximum Value in a Grid (greedy)
Thanks for the video, helped me out. keep up the good work! 🌸
I have a doubt why we cannot make prefix sum of size same as nums size, why we initialize prefix sum 0 at 0 index
It's also ok without zero padding, we can prepare a padding 0 for easy handle edge cases, like prefix sum from index 2 - index 0, if no zero padding, you need to have the edge cases check and add more lines of code. if it has no index 0 padding, you need the if check to check if it is zero.
Thank you bro, this solution really helped me...
Nice explanation!
thank you!
good idea bro thanks
thanks broo
Nyc Explaination Bro
Thanks
good explanation = thank you so much❤❤❤ please keep doing this kind of videos , because are very helpful for us
thanks, I'll continue to improve the content and quality of the video.
Thanks a lot!!!!! <3
code does work when hamsters =".HH.H.H.H.."
tested, works class Solution: def minimumBuckets(self, hamsters: str) -> int: n = len(hamsters) i, res = 0, 0 while i < n: if hamsters[i] == 'H': if i + 1 < n and hamsters[i + 1] == '.': i += 2 res += 1 elif i - 1 >= 0 and hamsters[i - 1] == '.': res += 1 else: return -1 i += 1 return res
promo sm
Thank you so much for the video! It really helped me learn sliding window, such a smart way to solve it, the logic behind it is quite tricky though.
Nice Explanation
Great solution and easy to understand thanks for the whiteboard explanation.
Glad it was helpful!
So far. easiest explanation found on youtube ..Thanks !
great solution and explanation!
Glad it helped!
Can we use vanilla dijkstra instead?
yes, we can.
Thanks, good explanation
Glad it was helpful!
it is not binary search solution((
hmm, maybe recursive or quick power is a good name
Explained it in precise and concise manner ..amazing
your channel is a goldmine got my weekends covered now🙏
Thanks, I’ll continued the improvement, practice makes perfect!
Thanks
The time complexity is O(n^4), sorry for that I didn't solve it online, after carefully checking, it should be this: we have s1, s2 with cache, it's n^2, we have for loop, it's now n^3, but we also have s1 == s2, it's another O(n), so the time complexity is O(n^4), if you have any questions, please make a comment.
awesome bro.....thankx
time is O(m + n)
Time is O(n^2), there is for loop inside.
Cool video, thanks!
Glad you liked it!
I think they have added new test cases to this problem, this solution gives TLE now. But my intuition is that you can actually abstract the inner for-loop into its own method (example: def parseSubstring(...){}. If the for-loop in this new method is somehow transformed into a recursive call, then you can add @cache decorator above the new parseSubstring(...) method signature to memoize the results and prevent TLE. I'm too lazy to spend time implementing this though since I'd rather use my time to review other problems for my Amazon on-site lol.....
I've justed checked in .com and .cn, they're both ok in python. here is the code, you can have check. class Solution: def longestValidSubstring(self, word: str, forbidden: List[str]) -> int: forbidden = set(forbidden) # n * m ** 2 l, res = 0, 0 for r in range(len(word)): for i in range(r, max(r - 10, l - 1), -1): if word[i: r + 1] in forbidden: l = i + 1 break res = max(res, r - l + 1) return res
This really helped me understand this problem better, thanks
Beautiful solution thank you for making a video for this problem
Using python?
yes
Which language is it
python
Thankyou for these videos great help
hey if possible can u please guide my comp. sci journey , im a first year student
grasp one language such as Python, then be really good at cources of data structure and algorithms and algorithms design, then grind leetcode 75 and look for internship as early as possible
@@letscode1000 thank you
It's the same for res = [] or self.res = [] for python global variable
"Answers within 10^-6 of the actual....." --> nice way to identify a potential Binary Search problem :) This would work for the Sqrt(n) problem too. But unfortunately not for Koko Banana or Aggressive Cows
yes, I agree, this problem is recognized by binary search not only by the 10^-6 but also the Minimize Max key word, in my video Koko eating banana: czcams.com/video/dPEimZw_BnQ/video.html, I also explained how to recognize as binary search + guess problems, the coding is easy, the hard part is to recognize the pattern.
wait i forgot about this one.Ty so much!!
it's a famous template problem in cs for practising dfs😄
@@letscode1000 yes i see
Nice work man, very clean solution. Your English and explanation is very good 👍
Space complexity O(mn), dfs will call at most m*n times
Hey, I love what you doing. Keep it up. Love the content.
Very good vid
thanks
Mistake for analyzing the r value, it should be 2 * 10 ** 8, not 10 ** 16, I made a mistake by 10 ** 8 + 10 ** 8 = 10 ** 16.
Time complexity is O(nlogn) not O(n), heappush and heappop is log(N)
correction: space complexity O(n*k)
fire ❤❤❤❤
i totally understand your logic.. can you give solution in c++
Thank you, very well explained!
A better solution is to use message as a buffer. class Logger: def __init__(self): self.logger_set = set() self.message_queue = deque() def shouldPrintMessage(self, timestamp: int, message: str) -> bool: while self.message_queue: oldest_message, oldest_time = self.message_queue[0] if timestamp - oldest_time >= 10: self.message_queue.popleft() self.logger_set.remove(oldest_message) else: break if message not in self.logger_set: self.logger_set.add(message) self.message_queue.append((message, timestamp)) return True else: return False
Horrible. The map would keep grow until system is out of memory. This kind of implementation should be done using a ring buffer or something.
good point, this is the buffer - the queue message application for solving the memory issues. class Logger: def __init__(self): self.logger_set = set() self.message_queue = deque() def shouldPrintMessage(self, timestamp: int, message: str) -> bool: while self.message_queue: oldest_message, oldest_time = self.message_queue[0] if timestamp - oldest_time >= 10: self.message_queue.popleft() self.logger_set.remove(oldest_message) else: break if message not in self.logger_set: self.logger_set.add(message) self.message_queue.append((message, timestamp)) return True else: return False