2 Pointers Algorithm - DSA Course in Python Lecture 12

  Рет қаралды 18,435

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 21
@GregHogg
@GregHogg 5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@TJ-jh6xx
@TJ-jh6xx 4 күн бұрын
Clean solution, thanks! As an improvement, I think you can skip the reverse step completely if you just use insert instead of append: array.insert(0,value). So, basically insert at the front of the array each time instead of append which inserts at the end, requiring the reverse later.
@docsmate2umass
@docsmate2umass 19 күн бұрын
simple and clear explanation makes this video more valuable .
@BigStupidTech
@BigStupidTech 5 ай бұрын
Spitting straight value. Thanks for these
@GregHogg
@GregHogg 5 ай бұрын
It's what I do
@Schadenfreude596
@Schadenfreude596 17 күн бұрын
I like to watch your videos non-decreasing order
@Za3DoRzX
@Za3DoRzX Ай бұрын
I love your explanations Greg, keep up the good work.
@majestif
@majestif 5 ай бұрын
Many thanks for a great explanation!
@GregHogg
@GregHogg 5 ай бұрын
You're very welcome 🥰
@christianjt7018
@christianjt7018 5 ай бұрын
Great explanation, thanks a lot for sharing
@leandrormor
@leandrormor 5 ай бұрын
Thanks, your content is brilliant. I hope you'll touch monotonic stack, double heap, prefix sum...
@nurbekmalikov3467
@nurbekmalikov3467 2 ай бұрын
for space comp just create one iteration index like => iterator = len(num) -1 and every greater value puts original array which is num and iterator-- this is O(1) space!
@MrTo1223
@MrTo1223 22 күн бұрын
Hi greg can I just change th3 conditions to append the smallest of the squares of the left and right pointers?
@helloworldcsofficial
@helloworldcsofficial Ай бұрын
Thanks! Will there be more easy and medium problems where we can I apply the two pointer (indices) technique?
@RaviPrakash-dz9fm
@RaviPrakash-dz9fm Күн бұрын
Is this good? from typing import List def squares(array : List[int]) -> List[int]: n = len(array) l = 0 r = n - 1 for i in range(len(array)): array[i] = array[i]**2 while l < r: start = array[l] end = array[r] if end < start: array[l] , array[r] = array[r] , array[l] r -= 1 return array squares([-4, -1, 0, 3, 10]) I tried not to use extra space. I am just learning so I might have missed some edge case
@ryanlalliss5977
@ryanlalliss5977 5 ай бұрын
Sorry if this is stupid but why not use the insert method instead of append rather than reverse the array at the end?
@GregHogg
@GregHogg 5 ай бұрын
That will be inefficient because inserting at beginning is slow
@izzya1282
@izzya1282 4 ай бұрын
Perfectooo amigo
@timkvernen4852
@timkvernen4852 5 ай бұрын
It's not accurate to say that the biggest values are on the outside. The second biggest value could be the second or second-to-last element. It would be accurate to say that the biggest value will always be on the outside.
@abodora532
@abodora532 5 ай бұрын
hmm, but what if they weren't in non decreasing order
@divyanshsingh6668
@divyanshsingh6668 5 ай бұрын
Sort
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
3Sum - Leetcode 15 - 2 Pointers (Python)
9:42
Greg Hogg
Рет қаралды 14 М.
Prefix Sum in 4 minutes | LeetCode Pattern
4:13
AlgoMasterIO
Рет қаралды 16 М.
How to Use the Two Pointer Technique
10:56
Team AlgoDaily
Рет қаралды 117 М.
Pointers in Python Are A Real Thing
8:51
NeuralNine
Рет қаралды 24 М.
Two Pointer Algorithm | Two Sum Problem | Solve DS Problems in O(N) Time
19:18
JAVAAID - Coding Interview Preparation
Рет қаралды 123 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 724 М.
ML Was Hard Until I Learned These 5 Secrets!
13:11
Boris Meinardus
Рет қаралды 354 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 156 М.