Reverse Prefix of Word (LeetCode 2000) | Full Solution with stack data structure

  Рет қаралды 972

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Join this channel to get access to perks: / @nikoo28
Actual problem on LeetCode: leetcode.com/problems/reverse...
Chapters:
00:00 - Intro
00:43 - Problem Statement
03:12 - Using Stack Data Structure
06:24 - Dry-run of Code
08:19 - Final Thoughts
📚 Links to topics I talk about in the video:
Stack Data Structure: • Stack Data Structure e...
What is Big O?: • Big O Notation Simplif...
Other Easy Problems: • Easy Problems
📘 A text based explanation is available at: studyalgorithms.com
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/3sJm8Wl
Favorite book to understand algorithms: amzn.to/4848xJH
Favorite book for data structures: amzn.to/3P96YBv
Get started for interview preparation: amzn.to/44Nn5du
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3PdsViT
Microphone: amzn.to/3Exv83x
Recording Camera: amzn.to/3PwyN8e
Tablet to sketch and draw: amzn.to/3ZdKVy7
Sketching Tool: amzn.to/45XJEgY
Laptop to edit videos: amzn.to/460ofDu
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#leetcode #programming #interview

Пікірлер: 10
@unemployedcse3514
@unemployedcse3514 2 ай бұрын
awesome ❤
@AliRaza-gh3hp
@AliRaza-gh3hp 2 ай бұрын
Brother You are doing awesome work for students like us please keep going. can you please do the problem 6. Zizag Conversion on leetcode. I will be thankful.
@akankshasonkar6846
@akankshasonkar6846 2 ай бұрын
Nice solution Nikhil :)
@arupgope2676
@arupgope2676 2 күн бұрын
I solve it using 2 pointer
@rdrahuldhiman19
@rdrahuldhiman19 2 ай бұрын
I hope your eye heals quickly
@nikoo28
@nikoo28 2 ай бұрын
thanks a lot for the good wishes...the eye infection caused me some delay to publish videos. Thanks for being a viewer of my channel and your patience :)
@hemanthcse1
@hemanthcse1 2 ай бұрын
We can achieve this without using extra space like stack fun reversePrefixSolution3(word: String, ch: Char): String { val firstOccurrence = word.indexOf(ch) if (firstOccurrence == -1){ return word } val result = CharArray(word.length) for (i in 0..firstOccurrence){ result[i] = word[firstOccurrence-i] } for (i in (firstOccurrence+1) until word.length){ result[i] = word[i] } return String(result) } correct me if i am wrong
@nikoo28
@nikoo28 2 ай бұрын
When you use the charArray it does take up extra O(n) space. So the time complexity remains the same
@anuragrawat4350
@anuragrawat4350 2 ай бұрын
int index = word.indexOf(ch) if(index != -1){ return new StringBuilder(word.substring(0,index+1).reverse).toString() + word(substring(index+1,word.length())); } return word;
@user-yl4vp2ox8v
@user-yl4vp2ox8v 2 ай бұрын
// Online C compiler to run C program online #include #include void swap(char *p, char *q) { int temp; while ( p < q) { temp = *p ; *p++ = *q; *q-- = temp; } } char * fun_ub(char arr[], char p , int len) { int i = 0 ; while ( arr[i]!= '\0') { if ( arr[i] == 'd') { swap( &arr[0], &arr[i]); break; } i++; } return arr; } int main() { char arr[] = "abcdefd"; char a = 'd'; int stl = strlen(arr)-1; char *p = fun_ub(arr, a , stl); printf("%s", p); }
Max Consecutive Ones (LeetCode 1004) | Full Solution w/ animations
14:41
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 30 МЛН
Doing This Instead Of Studying.. 😳
00:12
Jojo Sim
Рет қаралды 26 МЛН
Это реально работает?!
00:33
БРУНО
Рет қаралды 4,2 МЛН
Little brothers couldn't stay calm when they noticed a bin lorry #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 7 МЛН
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 600 М.
Leetcode 46. Permutations : Introduction to backtracking
10:06
ComputerBread
Рет қаралды 91 М.
Understanding B-Trees: The Data Structure Behind Modern Databases
12:39
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 465 М.
Advice from the Top 1% of Software Engineers
10:21
Kevin Naughton Jr.
Рет қаралды 3,3 МЛН
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 30 МЛН