HelmyCodeCamp
HelmyCodeCamp
  • 54
  • 94 237
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.
มุมมอง: 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 155. Min Stack - Python
มุมมอง 1.3K3 ปีที่แล้ว
Leetcode 155. Min Stack - Python
Leetcode 279. Perfect Squares - Python
มุมมอง 5733 ปีที่แล้ว
Leetcode 279. Perfect Squares - 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

ความคิดเห็น

  • @j.c.4191
    @j.c.4191 24 วันที่ผ่านมา

    Really good explanation!

  • @adityakulkarni5577
    @adityakulkarni5577 25 วันที่ผ่านมา

    You can do it in O(1) time O(N) space using a queue.

  • @ИльяСмирнов-ж8я
    @ИльяСмирнов-ж8я 3 หลายเดือนก่อน

    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.

  • @mohakkapoor8403
    @mohakkapoor8403 3 หลายเดือนก่อน

    great

  • @samirpandit8899
    @samirpandit8899 3 หลายเดือนก่อน

    beautifullll

  • @Thegreenone223
    @Thegreenone223 4 หลายเดือนก่อน

    Thank you

  • @adityavikramsingh5498
    @adityavikramsingh5498 5 หลายเดือนก่อน

    Great explanation! Question: are we using the size as the tail of the linked list?

  • @mheyrie
    @mheyrie 6 หลายเดือนก่อน

    Your explanation is by far the easiest to understand. thank you

  • @bhonekhantnaing7016
    @bhonekhantnaing7016 6 หลายเดือนก่อน

    thanksss,

  • @cakeezz
    @cakeezz 6 หลายเดือนก่อน

    Thank you! :)

  • @shaziakaleem1895
    @shaziakaleem1895 8 หลายเดือนก่อน

    Good explanation with clean code. Thank you _/\_

  • @riske4359
    @riske4359 10 หลายเดือนก่อน

    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

  • @Dishum_dishum
    @Dishum_dishum 10 หลายเดือนก่อน

    Your explanation is top notch 🛐

  • @CyrusWong-yq4uw
    @CyrusWong-yq4uw 11 หลายเดือนก่อน

    Worst solution seen so far

  • @dgimop
    @dgimop ปีที่แล้ว

    Nicely explained

  • @ceezee1229
    @ceezee1229 ปีที่แล้ว

    how does it work if it's in a separate file?

  • @kiitanayandosu-ug7pe
    @kiitanayandosu-ug7pe ปีที่แล้ว

    Amazing explanation

    • @maged_helmy
      @maged_helmy ปีที่แล้ว

      Glad it was helpful!

  • @mark.AI404
    @mark.AI404 ปีที่แล้ว

    Thank you <3

  • @laisdeghaide9853
    @laisdeghaide9853 ปีที่แล้ว

    how does this code guarantee the shortest distance?

    • @clancy2570
      @clancy2570 9 หลายเดือนก่อน

      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.

  • @varcel4625
    @varcel4625 ปีที่แล้ว

    Your brains are on another leve.

  • @tsuulifts
    @tsuulifts ปีที่แล้ว

    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

    • @maged_helmy
      @maged_helmy ปีที่แล้ว

      Glad you enjoyed it!

  • @jeffjames15
    @jeffjames15 ปีที่แล้ว

    beautiful

    • @maged_helmy
      @maged_helmy ปีที่แล้ว

      Thank you! Cheers!

  • @nithinma8697
    @nithinma8697 ปีที่แล้ว

    Very good Explanation for Beginners

  • @nikitasinha8181
    @nikitasinha8181 ปีที่แล้ว

    Thank you so much

    • @maged_helmy
      @maged_helmy ปีที่แล้ว

      You're most welcome

  • @santhakumar20
    @santhakumar20 ปีที่แล้ว

    such a awesome explanation ...

  • @ishanbanjara734
    @ishanbanjara734 ปีที่แล้ว

    Thank you so much sir... I loved it!

  • @narindersharma303
    @narindersharma303 ปีที่แล้ว

    much easier approach

  • @aryanverma2876
    @aryanverma2876 ปีที่แล้ว

    great explanation : )

  • @tomleeyrc40
    @tomleeyrc40 ปีที่แล้ว

    This reminds me of the towers of hanoi solution, thank you for this explanation

  • @funfingen
    @funfingen ปีที่แล้ว

    This was one of the best explanations I have seen! P.S. Your linkedin link doesn't work.

    • @maged_helmy
      @maged_helmy ปีที่แล้ว

      Thank you! I have now fixed that

  • @vantrongvo6468
    @vantrongvo6468 ปีที่แล้ว

    very clear explanation, thanks

  • @gurunathreddy6908
    @gurunathreddy6908 ปีที่แล้ว

    Thank you so much such a wonderful explanation

  • @sriharsha2027
    @sriharsha2027 2 ปีที่แล้ว

    Very easy and Understandable solution thank you.

  • @sriharsha2027
    @sriharsha2027 2 ปีที่แล้ว

    Thanks a lot bro your explanation is very good

  • @RAJUBHAI-ww7em
    @RAJUBHAI-ww7em 2 ปีที่แล้ว

    Holy Thanks mate

  • @pythonicd1239
    @pythonicd1239 2 ปีที่แล้ว

    I got memory limit exceeded for the same code but thanks for the video

  • @khalilsleimi7832
    @khalilsleimi7832 2 ปีที่แล้ว

    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

  • @johnmauricio8490
    @johnmauricio8490 2 ปีที่แล้ว

    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.

  • @Zephromonia
    @Zephromonia 2 ปีที่แล้ว

    Thanks for the tutorial! This helped me understand.

  • @lucynowacki3327
    @lucynowacki3327 2 ปีที่แล้ว

    .push() is O(n) , .pop() is O(1)

  • @sonamuh
    @sonamuh 2 ปีที่แล้ว

    thank you!!!!

  • @mitramir5182
    @mitramir5182 2 ปีที่แล้ว

    Thank you so much, I was really lost since I've just started learning about data structures! but your explanation was amazing!

  • @Guy9221
    @Guy9221 2 ปีที่แล้ว

    Time complexity analysis?

  • @ahmadmohamadi
    @ahmadmohamadi 2 ปีที่แล้ว

    Whats the Complexity of this solution?

  • @chanyaoc
    @chanyaoc 2 ปีที่แล้ว

    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!

  • @adventurer2395
    @adventurer2395 2 ปีที่แล้ว

    You don't wanna be recalculating the row and col len with every recursive call.

  • @Vickydan23
    @Vickydan23 2 ปีที่แล้ว

    hi, please why is it -self.size

    • @anand8412
      @anand8412 2 ปีที่แล้ว

      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.

  • @peternguyen9995
    @peternguyen9995 2 ปีที่แล้ว

    Not only do you explained it quite well, but your voice is also quite soothing, which makes the lesson enjoyable.

  • @gehadmustafa6786
    @gehadmustafa6786 2 ปีที่แล้ว

    Thanks a lot : )

  • @nagendrabommireddi8437
    @nagendrabommireddi8437 2 ปีที่แล้ว

    thank you