Adding Spaces to a String - Leetcode 2109 - Python

  Рет қаралды 6,068

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 26
@turboch-711
@turboch-711 Ай бұрын
Are you doing okay today? You don't have to upload a video if you don't feel good. Take the day off my man
@steven8
@steven8 Ай бұрын
I think it's easier if you use slicing to extract each substring and then join the substrings with a space: res = [] prev_start = 0 for end in spaces: res.append(s[prev_start:end]) prev_start = end res.append(s[prev_start:]) return " ".join(res)
@TheMarcelism
@TheMarcelism Ай бұрын
Great and simpler and easy to understand. Thanks!
@sdemji
@sdemji Ай бұрын
dynamic arrays are the main culprit for the bad runtime, reallocation happens in the background when pushing elements, or checks for reallocation and bookkeeping operations, so even tho yhou brushed it over at the beginning, a three pointer approach with a fixed sized array would probably perform better. Ohter than that, class on grass
@hargovind2776
@hargovind2776 Ай бұрын
Yeah bro Take care, get some break and rest, clear your mind
@lightlegion_
@lightlegion_ Ай бұрын
It's impressive how fantastic your content is!
@madhurkhyani9671
@madhurkhyani9671 Ай бұрын
def addSpaces(self, s: str, spaces: List[int]) -> str: ans="" idx=0 for i,char in enumerate(s): if idx
@aaryatupe007
@aaryatupe007 Ай бұрын
Thank you for posting such tutorials ! You are amazing
@ThinkOutsideTheBox12345
@ThinkOutsideTheBox12345 Ай бұрын
Awesome Explanation!!!
@__samuel-cavalcanti__
@__samuel-cavalcanti__ Ай бұрын
Why this approach is better than creating a new array or spaces with m+n size then just copying ?
@ahmedtremo
@ahmedtremo Ай бұрын
Thanks man
@Ogrizkov
@Ogrizkov Ай бұрын
Why would you iterate each character if you could use slicing. In Java yes, two pointer approach more efficient than substring
@lendr.o
@lendr.o Ай бұрын
can you do 2382, been struggling with this one
@potansiyel7021
@potansiyel7021 Ай бұрын
We need to research your brain. I think your brain has changed after all these leetcode questions.
@mrf92
@mrf92 Ай бұрын
bro you solve POTD when the question is reasonable then discontinue when the question is actually hard. why??
@jad_c
@jad_c Ай бұрын
he doesn't owe you anything
@ajaygupta6034
@ajaygupta6034 Ай бұрын
he's trying his best to manage things, don't doubt him, he could've recorded this video earlier as the POTD solution comes in editorial a few days before. He can't sacrifice himself for you, someone who doesn't even value his hardwork!!! (Thanks for the great explanations Neet!)
@mrf92
@mrf92 Ай бұрын
@@ajaygupta6034 look I feel bound to reply back, because this comment is made highlighted by the creator. I asked this question because he said earlier he loved making leetcode videos over his job in google/Amazon. Now It's not like I or someone else is dependent on this account to solve leetcode problems. generally I solved a problem on my own then, sometimes throw a glimpse on different solution videos, editorial, for any new approach that I ain't familiar with before. I myself solved over 1k leetcode problems. brother don't think you are indispensable, no one actually is in this world. don't get arrogant, keep your foot on the land.
@ajaygupta6034
@ajaygupta6034 Ай бұрын
​@@mrf92 First of all, I'm sorry if I came across as arrogant, although I'm not talking about myself at all. Yes, fosure finding new approaches to problem is one of the joys of leetcode, but all I am saying is respect that dude, he doesn't look like someone who just quits when the obstacle is tough lol, but sometimes you're just not left with enough to do things you love unless you do them at your expense, and I think he's been doing that already for some time, so cut the guy some slack lol. Also how were you able to see highlighted by creator, like what's that?
@aaryatupe007
@aaryatupe007 Ай бұрын
Hi, I need help with these questions: Maximum Frequency of an Element After Performing Operations I and Adjacent Increasing Subarrays Detection II. Please could you provide a tutorial on this!!
@rsaisiddhu
@rsaisiddhu Ай бұрын
Hello I have uploaded my explanation in my KZbin channel - kzbin.info/www/bejne/ZmKZgKSHbJ6mp5Ysi=Jxvo8OhISE2eRhZS May this helps
@leeroymlg4692
@leeroymlg4692 Ай бұрын
I found my solution to be a little bit simpler: res = [] p = 0 for i in range(len(s)): if p < len(spaces) and i == spaces[p]: res.append(" ") p += 1 res.append(s[i]) return '"".join(res)
@davi_singh
@davi_singh Ай бұрын
My solution was almost the same as yours :D. Happy to see I am catching up a little ``` res = '' space_idx = 0 for i, c in enumerate(s): if space_idx < len(spaces) and i == spaces[space_idx]: res += ' ' space_idx += 1 res += c return res ``` I was using a string on purpose as I thought it would be more efficient but looks like i need to go deeper into that part
@Ogrizkov
@Ogrizkov Ай бұрын
Allocate a list in size of spaces length
Shifting Letters II - Leetcode 2381 - Python
19:07
NeetCodeIO
Рет қаралды 4,6 М.
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 187 М.
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
25 nooby Python habits you need to ditch
9:12
mCoding
Рет қаралды 1,8 МЛН
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 777 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 157 М.
*Next-door 10x Software Engineer* [FULL]
4:50
Programmers are also human
Рет қаралды 869 М.
AI Is Not Designed for You
8:29
No Boilerplate
Рет қаралды 274 М.
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 146 М.
How I Approach a New Leetcode Problem (live problem solving)
25:31
70% of Programmers can't solve this LeetCode Easy Question
7:32
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 339 М.