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,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 155. Min Stack - Python
Переглядів 1,3 тис.3 роки тому
Leetcode 155. Min Stack - 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

КОМЕНТАРІ

  • @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 UA-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

  • @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

  • @jeffjames15
    @jeffjames15 Рік тому

    beautiful

  • @nithinma8697
    @nithinma8697 Рік тому

    Very good Explanation for Beginners

  • @nikitasinha8181
    @nikitasinha8181 Рік тому

    Thank you so much

  • @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