- 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,2 тис.3 роки тому
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,3 тис.3 роки тому
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,7 тис.3 роки тому
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,6 тис.3 роки тому
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
Переглядів 8 тис.3 роки тому
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
Переглядів 24 тис.3 роки тому
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
Переглядів 6 тис.3 роки тому
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,7 тис.3 роки тому
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
Переглядів 13 тис.3 роки тому
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,3 тис.3 роки тому
Leetcode 739. Daily Temperatures - Python
Leetcode 20. Valid Parentheses - Python
Переглядів 4583 роки тому
Leetcode 20. Valid Parentheses - Python
Leetcode 279. Perfect Squares - Python
Переглядів 5733 роки тому
Leetcode 279. Perfect Squares - Python
Leetcode 200. Number of Islands - Python DFS
Переглядів 1,1 тис.3 роки тому
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,6 тис.3 роки тому
Leetcode 346. Moving Average from Data Stream - Python
Leetcode 622. Design Circular Queue - Python
Переглядів 1,5 тис.3 роки тому
Leetcode 622. Design Circular Queue - Python
Parallelize your Python code in under 3 minutes with this simple trick using Ray!
Переглядів 1,1 тис.3 роки тому
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 UA-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