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

  Рет қаралды 1,362

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 11
@IshaZaka
@IshaZaka 2 ай бұрын
Hi Nikhil, plz make for hard challegnes as well
@AliRaza-gh3hp
@AliRaza-gh3hp 6 ай бұрын
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.
@unemployedcse3514
@unemployedcse3514 5 ай бұрын
awesome ❤
@akankshasonkar6846
@akankshasonkar6846 5 ай бұрын
Nice solution Nikhil :)
@rdrahuldhiman19
@rdrahuldhiman19 6 ай бұрын
I hope your eye heals quickly
@nikoo28
@nikoo28 6 ай бұрын
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 :)
@arupgope2676
@arupgope2676 3 ай бұрын
I solve it using 2 pointer
@hemanthcse1
@hemanthcse1 6 ай бұрын
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 6 ай бұрын
When you use the charArray it does take up extra O(n) space. So the time complexity remains the same
@anuragrawat4350
@anuragrawat4350 6 ай бұрын
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;
@RameshGaridapuri
@RameshGaridapuri 6 ай бұрын
// 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); }
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 27 МЛН
Real Man relocate to Remote Controlled Car 👨🏻➡️🚙🕹️ #builderc
00:24
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 678 М.
3.6 Infix to Postfix using Stack | Data Structures Tutorials
20:10
Jenny's Lectures CS IT
Рет қаралды 1,8 МЛН
Advice from the Top 1% of Software Engineers
10:21
Kevin Naughton Jr.
Рет қаралды 3,4 МЛН
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 572 М.
5 Patterns to Master 80% of Leetcode Problems
15:37
Rahul Pandey
Рет қаралды 7 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 233 М.
why are switch statements so HECKIN fast?
11:03
Low Level
Рет қаралды 427 М.
What type of pedestrian are you?😄 #tiktok #elsarca
00:28
Elsa Arca
Рет қаралды 27 МЛН