- 54
- 94 237
HelmyCodeCamp
Norway
เข้าร่วมเมื่อ 13 มี.ค. 2016
Hi and Welcome to my Channel :)
I create Computer Science and Machine Learning step-by-step code tutorials. Feel free to get in touch with me on LinkedIn or reach out if you have any questions.
I create Computer Science and Machine Learning step-by-step code tutorials. Feel free to get in touch with me on LinkedIn or reach out if you have any questions.
33. Search in Rotated Sorted Array - Python
There is an integer array nums sorted in ascending order (with distinct values).
Given the array nums after the rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.
You must write an algorithm with O(log n) runtime complexity.
Given the array nums after the rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.
You must write an algorithm with O(log n) runtime complexity.
มุมมอง: 134
วีดีโอ
LeetCode 152. Maximum Product Subarray - Python
มุมมอง 5323 ปีที่แล้ว
Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, and return the product. It is guaranteed that the answer will fit in a 32-bit integer. A subarray is a contiguous subsequence of the array.
LeetCode 49. Group Anagrams - Python
มุมมอง 9923 ปีที่แล้ว
Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
LeetCode 56. Merge Intervals - Python
มุมมอง 2113 ปีที่แล้ว
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input.
LeetCode 15. 3Sum
มุมมอง 1.2K3 ปีที่แล้ว
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] nums[j] nums[k] 0. Notice that the solution set must not contain duplicate triplets.
LeetCode 53. Maximum Subarray - Python
มุมมอง 1.3K3 ปีที่แล้ว
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array.
LeetCode: 242. Valid Anagram - Python
มุมมอง 1.7K3 ปีที่แล้ว
Given two strings s and t, return true if t is an anagram of s, and false otherwise.
121. Best Time to Buy and Sell Stock - Python
มุมมอง 5953 ปีที่แล้ว
You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
LeetCode 217. Contains Duplicate: Python 2 simple solutions
มุมมอง 1.6K3 ปีที่แล้ว
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
Leetcode 1. Two Sum - Python Simple Solution
มุมมอง 8K3 ปีที่แล้ว
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.
LeetCode 841. Keys and Rooms - Python
มุมมอง 8413 ปีที่แล้ว
There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key. When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms. Given an array...
Leetcode 542. 01 Matrix - Python
มุมมอง 24K3 ปีที่แล้ว
Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1.
Leetcode 733. Flood Fill - Python
มุมมอง 6K3 ปีที่แล้ว
An image is represented by an m x n integer grid image where image[i][j] represents the pixel value of the image. You are also given three integers sr, sc, and newColor. You should perform a flood fill on the image starting from the pixel image[sr][sc]. To perform a flood fill, consider the starting pixel, plus any pixels connected 4-directionally to the starting pixel of the same color as the ...
Leetcode 394. Decode String - Python
มุมมอง 8753 ปีที่แล้ว
Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data...
Leetcode 225. Implement Stack using Queues - Python
มุมมอง 2.7K3 ปีที่แล้ว
Implement a last-in-first-out (LIFO) stack using only two queues. The implemented stack should support all the functions of a normal stack (push, top, pop, and empty). Implement the MyStack class: void push(int x) Pushes element x to the top of the stack. int pop() Removes the element on the top of the stack and returns it. int top() Returns the element on the top of the stack. boolean empty() ...
Leetcode 232. Implement Queue using Stacks - Python
มุมมอง 13K3 ปีที่แล้ว
Leetcode 232. Implement Queue using Stacks - Python
Leetcode 150. Evaluate Reverse Polish Notation - Python
มุมมอง 6423 ปีที่แล้ว
Leetcode 150. Evaluate Reverse Polish Notation - Python
Leetcode 739. Daily Temperatures - Python
มุมมอง 1.3K3 ปีที่แล้ว
Leetcode 739. Daily Temperatures - Python
Leetcode 20. Valid Parentheses - Python
มุมมอง 4583 ปีที่แล้ว
Leetcode 20. Valid Parentheses - Python
Leetcode 200. Number of Islands - Python DFS
มุมมอง 1.1K3 ปีที่แล้ว
Leetcode 200. Number of Islands - Python DFS
Leetcode 286. Walls and Gates (BFS - Python)
มุมมอง 4093 ปีที่แล้ว
Leetcode 286. Walls and Gates (BFS - Python)
Leetcode 346. Moving Average from Data Stream - Python
มุมมอง 4.6K3 ปีที่แล้ว
Leetcode 346. Moving Average from Data Stream - Python
Leetcode 622. Design Circular Queue - Python
มุมมอง 1.5K3 ปีที่แล้ว
Leetcode 622. Design Circular Queue - Python
Parallelize your Python code in under 3 minutes with this simple trick using Ray!
มุมมอง 1.1K3 ปีที่แล้ว
Parallelize your Python code in under 3 minutes with this simple trick using Ray!
LeetCode Tutorial 138. Copy List with Random Pointer - Python Explanation
มุมมอง 9544 ปีที่แล้ว
LeetCode Tutorial 138. Copy List with Random Pointer - Python Explanation
LeetCode 708. Insert into a Cyclic Sorted List - Python
มุมมอง 9354 ปีที่แล้ว
LeetCode 708. Insert into a Cyclic Sorted List - Python
LeetCode 430. Flatten a Multilevel Doubly Linked List - Python Explained
มุมมอง 3124 ปีที่แล้ว
LeetCode 430. Flatten a Multilevel Doubly Linked List - Python Explained
LeetCode Add Two Numbers Solution Explained - Python
มุมมอง 904 ปีที่แล้ว
LeetCode Add Two Numbers Solution Explained - Python
Really good explanation!
You can do it in O(1) time O(N) space using a queue.
This feeling then you are a completely noob in Python, went to TH-cam because you code didn't work... and see this video and think about pop(0) instead of the second stack.
great
beautifullll
Thank you
Great explanation! Question: are we using the size as the tail of the linked list?
Your explanation is by far the easiest to understand. thank you
thanksss,
Thank you! :)
Good explanation with clean code. Thank you _/\_
i just never seen a good explaination like this for dfs, you are just the best teacher in the universe. I think a baby can understand your explanation
Your explanation is top notch 🛐
Worst solution seen so far
Nicely explained
how does it work if it's in a separate file?
Amazing explanation
Glad it was helpful!
Thank you <3
Any time!
how does this code guarantee the shortest distance?
I was having a hard time understanding this at first, too. Basically, because in the second half our q at first only holds the coordinates of where we have 0s, so we find the #s that are next to the 0s, and thus one space away. Once we do this, all the spaces that are 1 space away from a zero now contain 1 and are added to our q. The for loop continues through and looks at the coordinates that now contain 1s and looks for any #s that may be next to them, and so on. Because we are starting at the 0s and working our way up within the q we will always find the shortest distance as the further ones will not be seen when we look up,down,left,right. I'm sure there's a better way to say it, but hopefully this can help someone a little.
Your brains are on another leve.
This is a very interesting and unique way to approach the problem, thanks for sharing I’ve learned a new way how to do it
Glad you enjoyed it!
beautiful
Thank you! Cheers!
Very good Explanation for Beginners
Glad you liked it
Thank you so much
You're most welcome
such a awesome explanation ...
Thank you so much sir... I loved it!
much easier approach
great explanation : )
This reminds me of the towers of hanoi solution, thank you for this explanation
This was one of the best explanations I have seen! P.S. Your linkedin link doesn't work.
Thank you! I have now fixed that
very clear explanation, thanks
Thank you so much such a wonderful explanation
Very easy and Understandable solution thank you.
Thanks a lot bro your explanation is very good
Holy Thanks mate
I got memory limit exceeded for the same code but thanks for the video
An alternative solution might be to have one stack hold input values, and the other stack holds the output values. You just add to the input stack when pushing. And when you need to peek or pop, you just check if the output stack is nonempty and return the poped/peeked value from that stack, otherwise, you flip the values from the input to the output and then pop/peek. Of course, it'll depend on where you want most of the computing to be spent, when writing data or when reading data
Hey man great video but you should focus more on the solution as opposed to explaining what parts of the code do syntatically. Anyone who is attempting leetcode mediums should already understand things like accessing an element in a 2D array.
Thanks for the tutorial! This helped me understand.
.push() is O(n) , .pop() is O(1)
thank you!!!!
Thank you so much, I was really lost since I've just started learning about data structures! but your explanation was amazing!
Time complexity analysis?
Whats the Complexity of this solution?
Thank you for the explanation. While this is algorithmically correct, it may fail in large test case. Specifically, if the distance of a cell is previously computed as 35 (exactly the ascii value of ‘#’), your code will mistakenly flag it as not being computed and therefore incrementing it again (and potentially more than once due to the same reason). I suggest you change ‘#’ to either some negative number or maximum of int so this corner case will be fine. Otherwise, love the short and concise explanation!
"#" != 35 in Python
You don't wanna be recalculating the row and col len with every recursive call.
hi, please why is it -self.size
lets say you have 7 elements in list. [10,11,12,13,14,15,16] and if you get 1-based index from reverse you get [-7,-6,-5,-4,-3,-2,-1]. so whenever you give negative index value in slicing like [-4:] it just get you all values from -4 index to end. so in this case [13,14,15,16]. You can read how slicing works in python lists. that will give you all others operations. In general [Initial:end:indexjump]. And if you give any negative numbers, then its just reversed 1 based index.
Not only do you explained it quite well, but your voice is also quite soothing, which makes the lesson enjoyable.
Thanks a lot : )
thank you