Length of Last Word | 2 Ways | Leetcode 58 | Amazon | codestorywithMIK

preview_player
Показать описание
This is the 7th Video of our Playlist "Solving only using C++ STLs/JAVA JCF".

In this video we will try to solve an easy String Problem :
Length of Last Word | Multiple Approaches | Leetcode 58 | Amazon | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Length of Last Word | Multiple Approaches | Leetcode 58 | Amazon | codestorywithMIK
Company Tags : AMAZON

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction
01:07 - Approach-1
02:53 - Approach-2 using STLs
11:27 - Coding it up

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024
Рекомендации по теме
Комментарии
Автор

Day 400 completed of yours, Mine 28, all bcz of you bhai

gauravmishra
Автор

Bhaiya ..can you please post the gfg POTD also . 🙏❤

Artiflex
Автор

Bhai biweekly contest ka 4th(3098. Find the Sum of Subsequence Powers) waale pe video banau na

dyashwanth
Автор

Thanks a lot bhaiya ❤❤ Congrats for 38k subs ❤❤

gauravbanerjee
Автор

please make video on (leetcode 310) minimum height trees

SameerKumar-nloy
Автор

Using the STL stringstream, we can easily get the output for this question :
class Solution {
public:
int lengthOfLastWord(string s) {
stringstream ss(s);
string token;
string last;
while( ss >> token){
last = token;
}
return last.size();
}
};

jigglewalasuzzyop
Автор

congratulations on 38k . you deserve millions.

aws_handles
Автор

much easier approach using stringstream...beats 100%


class Solution {
public:
int lengthOfLastWord(string s) {
stringstream ss(s);
string word;
string lastWord;


while (ss >> word) {
lastWord = word;
}
return lastWord.length();



}
};

TEJASSURYA-rv
Автор

sir aapne bola tha 50k hone par you will tell us how you started this channel. bhool mat jana . also face reveal kardo ab

souravjoshi
Автор

sir please cover the question : Minimum Window Subsequence

NonameNoname-ft
Автор

3097. Shortest Subarray With OR at Least K II Please Provide the Solution of this too ❤❤

utkarshsahay
Автор

bhaiya ji bina spos kere bhi toh chl rha lc pe

devmadaan
Автор

kya haal chaal bhai !! mere bolne pe hi "you can watch in 1.5x daala h na"

devmadaan
Автор

class Solution {
public int lengthOfLastWord(String s) {
s = s.stripTrailing();
int emptyIndex = s.lastIndexOf(' ');
return s.length() - emptyIndex - 1;
}
}

mohammedamansha
Автор

int lengthOfLastWord(string s) {
int n=s.size();
int len=0;
bool found=false;
for(int i=n-1; i>=0; i--){
if(s[i]!=' '){
len++;
found=true;
}
else if(found==true){
break;
}
}
return len;
}

SohailKhan-cxgb
Автор

Sir without using npos it gives right answer but sir when we subtract lastSpaceIdx from len then -1 then answer must be less than length of the string but it gives right answer as length of the string for the case when there is no space in the string.

abhishekbhadauriya
Автор

bhaiya agar time mile to weekly and biweekly contest ke q4 kara dena dono acche question hai, i was able to solve 4th in biweekly but go tle :(

dhairyachauhan
Автор

2035. Partition Array Into Two Arrays to Minimize Sum Difference:--->please make a tutorila on this, i have watched more than 10 videos but not able to understand...i request you...

____abhay_sharma___
Автор

int lengthOfLastWord(string s) {
istringstream iss(s);
string word;
vector <string>words;
while(iss>>word){
words.push_back(word);
}
if (words.empty()){
return 0;
}
else return words.back().size();
} is this good approach

yasharya
Автор

reverse while loop skip indexing
then next while loop count length if char is present i.e s[i] != ' '

just_a_guy