Text Justification | Broken into Pieces | GOOGLE | Leetcode-68 | Explanation + Live Coding
ฝัง
- เผยแพร่เมื่อ 22 ส.ค. 2024
- iPad PDF Notes - github.com/MAZ...
This is the 18th Video on our Strings Playlist.
In this video we will try to solve a very good, famous and irritating string problem "Text Justification" (Leetcode-68)
We will do live coding after explanation and see if we are able to pass all the test cases.
Problem Name : Text Justification
Company Tags : GOOGLE
My solutions on Github : github.com/MAZ...
Leetcode Link : leetcode.com/p...
My DP Concepts Playlist : • Roadmap for DP | How t...
My Graph Concepts Playlist : • Graph Concepts & Qns -...
My GitHub Repo for interview preparation : github.com/MAZ...
Subscribe to my channel : / @codestorywithmik
Instagram : / codestorywithmik
Facebook : / 100090524295846
Twitter : / cswithmik
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
#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
Thanks!
Thank you for such a nice gesture 😊
😮
@@user-ub2is4rs4x she has contributed so many times
Good afternoon MIK.. we as ur audience praise you a lot for ur teaching approach and for dry run, but one thing i always think after watching your solution how much effort and time invested and those sleepless nights you have gone through for practice and here you come with this kind of solution delivery..MIK you are literally an inspiration ❤
I couldn’t help but pin this comment for future. It’s emotional as to see you guys understand the effort spend on each video. I really appreciate those kind words.
It means everything to me.
I just aim to eliminate the dependency on Highly paid courses where students usually fall as a trap. Hope one day everyone will make use of this channel to build their skills on their own instead of paying huge fees to paid courses.
Thanks a lot Sachin.
And DSA is just the beginning.
1) More videos will come on System Design
2) Videos on Cloud tech stack etc. all are planned in my list for making us a complete developer
Thanks ❤️❤️❤️
Thank you so much for your effort MIK, we will support your effort from the bottom of our heart ❤
Your hard work hasn't gone unnoticed. We are with you wholeheartedly 🙏🙏
The unsung hero.
People will soon find this legend
We are with you MIK.
Your efforts have not gone unnoticed. I feel bad for those who are not aware of your channel.
king of DSA
iPad PDF Notes - github.com/MAZHARMIK/Interview_DS_Algo/blob/master/iPad%20PDF%20Notes/Leetcode068-Text%20Justification.pdf
******************************** JAVA ****************************************
class Solution {
int MAX_WIDTH;
public List fullJustify(String[] words, int maxWidth) {
List result = new ArrayList();
int n = words.length;
MAX_WIDTH = maxWidth;
int i = 0;
while(i < n) {
int lettersCount = words[i].length();
int j = i+1;
int spaceSlots = 0;
while(j < n && spaceSlots + lettersCount + words[j].length() + 1
this java solution gives TLE is that just with me ?
It looked easy, the way it is written. Below case i understood after putting exact case in console and ran.
The case when we have maxWidth=9, and two words of 4 chars each. In this case we are first considering 1 word and dont considering first space along with it. That's the catch. I appreciate the level of brain who thought this.
You just win my heart everytime. I mean how can someone break such a big problem into small easy chunks man. This is just amazing how you come up with such simplified explanations.
Thanks MIK... for such a wonderful explanation first time i was able to solve string hard problem my own just by watching the example explantion and dry run, thanks for such a wonderful and different content . I'm proud to be one of your subscriber and want to learn more from you. Thanks for your hardwork.
Means a lot 😇❤️🙏
@@codestorywithMIK Anything apart from TH-cam to get mentorship by you??
Actually currently I have not started any mentorship/guidance program etc.
I tried topmate for few days but recently i have to travel out of india multiple times and again I am travelling from end of this month till next to next month. It gets very difficult to take out time.
But i Will surely try and provide guidance classes to everyone .
@@codestorywithMIK Okay thanks for the hardwork you are putting for us , will always be grateful for this.
Can't get more cleaner code than this,, We are very grateful having you as Our mentor..
Proud to be your subscriber 🙏
Thanks a ton ❤️😇🙏
bhai bohot pyara explanation hai pura bohot acche se samajh aaya , really good work man !!
i have been watching your playlists and the upload that you do daily..and hatts off for the hard work you put in for us...always love the positive energy you spread calling the medium and hard questions easy ..that we can do it and ...especially you have the great explanation power ..I love the entirety of your teachings.. You deserve a million subscribers at least...thank you sir!
Means a lot 😇❤️🙏
Just Because of You i was able to do this question by my own in 1 hour.Thank You Bhaiya , Keep providing us valuable content.I also watched your video to know your intuition.
Here is My Java Code Let me know if it is good solution as interview purpose or not:-
class Solution {
public List fullJustify(String[] words, int maxWidth) {
List result=new ArrayList();
int i=0;
while(i=words.length){
StringBuilder s=new StringBuilder();
for(int k=i;k0){
space.append(" ");
}
s.append(words[j-1]+space);
}else{
s.append(words[j-1]);
int totalSpaces=maxWidth-s.toString().length();
StringBuilder space=new StringBuilder();
while(totalSpaces-->0){
space.append(" ");
}
s.append(space.toString());
}
result.add(s.toString());
break;
}
int spaceWidth=maxWidth-actualWidth;
int value=0;
if(totalWords-1!=0){
value=spaceWidth%(totalWords-1);
}
StringBuilder space=new StringBuilder();
int totalSpaces=0;
if(totalWords-1!=0){
totalSpaces=spaceWidth/(totalWords-1);
}
while(totalSpaces-->0){
space.append(" ");
}
StringBuilder s=new StringBuilder();
for(int k=i;k0){
space.append(" ");
}
s.append(words[j-1]+space.toString());
}else{
s.append(words[j-1]);
}
result.add(s.toString());
i=j;
}
return result;
}
}
Thank you so much 😇🙏
Just "gaddha" is enough to recall this problem 😁
Thanks for the simple explanation Mazhar.
😃 🙏
And alwasy THANK YOU so much for explanation. Your explanations are so good. I'm watching the video even after solving this. Kudos to you brother!
Thank you so much ❤️😇
Awesome video! Was seeing your videos since you have less than 1k subscribers! Really happy to see you grow 🤩
Means a lot.
Thank you so much for staying since the beginning ❤️
Roz video kholo , "Isme Medium/Hard marked hain but actually yeh question kaafi easy hain "
As Always Best Explanation 🔥
Thank you 🙌
Couldn't be more simpler than this. Love your content.
Most welcome 🙏❤️
recently i started to watch your video ,and your explanations are simple .👌
Means a lot 😇❤️🙏
Thanks a lot
mind blowing explanation your explanation style
is so good everyone understand very well. these students like me
not affordable to buy paid course. You are hope these students. Thank ❤🎉
Same. I can't afford huge fees of paid courses provided by scaler or any other online tutor.
This channel is a boon for us.
Glad I could help ❤️❤️
you are simply the best
thnx for the detailed soln.😇
Most welcome 😊
Crystal Clear 💎
Did this question on my own, although it took 2 hours to implement the whole approach.
So glad you implemented it on your own 💪
i was close to the approach but found implementaion to be typical
Nice video and perfect explanation as always for all the problems....
Thank you ❤️😇
@@codestorywithMIK Brother are you available at tonight for an 15 min 1-1 session on topmate.
Qustion kaafi achha tha. Aise questions se meri thinking aur coding skills imporve hoti he. Agar aise aur questions ho to please uski sheet mil sakti he? Edge cases kaafi irritating the, lekin question achha tha.
I totally agree.
Qns like these improve our ability to write clean and understandable code.
Sure thing, i will share more
correct
Thanks a lot that was so helpfull
Glad it helped😇
Exact same asked in Intuit oa yesterday hope I watched this vid earlier
Thank you for sharing this ❤️❤️❤️
Maza aa gaya. Thanks❤
I got this problem in "Hudson River Trading" company OA.
Wow
Thanks for sharing 🙏
First time I saw mik dislike a question and I can understand why !
Ha ha.
These qns are a little irritating.
But always remember, qns like these are ONLY ASKED TO CHECK YOUR ABILITY OF TWO THINGS :
1) If you can write clean and understandable code
2) How well you handle edge cases
I will try to share more such qns in my channel
Thank you for the solutions @@codestorywithMIK , I give credit to all the confidence that I gathered over the few months of solving tough problems like these to you. I know it will take time to solve such questions on my own but one step at a time with mik's guidance. Will surely do it one day.
Space : ❌
Gaddha : ✅
😁😁
It reminds me of Drake meme 🤓
@@codestorywithMIK That was my intention. 😊 Take a look at the meme I shared in the discussion section of this question. 🤣
Please share the link 😅
I want to see
ha ha sahi hai
Public class {
Public list full Justify(string ()words,int maxWidth){
list res=new Array list ();
list cur word =new Array list ();
int curlen=0;
for(string word:words){
if(curlen+word. length ()+curword.size()>max Width)
int total space =maxWidth-curlen;
int gap= cur word.size()-1;
if(gap==0){
res.add(cur.word.get(0)+" ".repeat(total space));
}else {
int space perGap=total space/gap;
int extra space =total space %gap;
string Builder line=new string Builder ();
for(int i=0;
i
Your solution was so easy to understand until you started using gadha as variable name. Entire flow broke because of that variable name. It took some extra time to understand the entire solution but really nice explaination.
My bad. I will take care from next time to not use such variables.
Thank you for your kind words 🙏🙏❤️❤️
Bro do you have 48 hours in a day. I am very very impressed with your consistentcy, Dedication, Energy. I am not that much consistent please bro make video on how you manage your time 😅
Means a lot 😇❤️
Sometimes it gets very difficult to to manage, so squeezing time from other tasks is the only option 😁
Same qn 😅
@@codestorywithMIK please start live video might be that will make mandatory
Thanks sir
good yar wowwww
Your code was ultra clean.😍
time complexity O(N^2) ? if we see while loop of j inside while loop of i, that way also O(N^2), and if we se that find line function inside the while loop of i, its again going for j times, so time complexity will be O(N^2), correct me or add some points :)
Definitely 👌
This belongs inside the while loop, right? cz we want as left as possible;
if(extra space > 0) {
s += " ";
extra space--;
}
It is being filled from left of the line only .
We are aware about how many spaces need to be filled after each word. That spaces are given. After that, when the spaces are done for a word in the line, we assign extra space to each (after word) if extra space > 0
bhaiya if possible along with leetcode dialy questions can u plan something for students to remove the fear of OA like solve some story based questions from hackerearth or take some OA questions from leetcode please nobody will explain this story based OA questions All youtubers are explaining DSA questions once think on my request and plan please bhaiya it will help lot of students
Hey,
Do you mean OA qn videos ?
@@codestorywithMIK yes sir
Just solving DSA questions is not enough to create impact if possible I an requesting you to solve OA questions sir please it will be a great help from your side for hardworking student
Definitely. Noted on this
Let me collect OAs and plan soon
@@codestorywithMIK now you are known for leetcode dialy challenge sir if u do OA questions atleast once in a day which involve some good algorithmic approach your channel will grow very fastly sir
Please launch a DSA course of advance level. I love your teaching sir.
good good
Can you make video on median of two sorted arrays
Can you please share leetcode link Pranay ?
wonderful bro.
Bhai apni real identity reveal kro.
Nice explanation! However, justify why you disliked the question.😂
Actually such qns take a lot of thought to cover corner cases and in interviews, it gets difficult to take care of all corner cases 😅
Such qns shouldn’t be asked or if they are asked, more time should be given 😄
Sir oa wale ques pe video banadoo plzz
Yaar itna acha koi kaise parha sakta hai
Sir when will u bring that topic wise questions which to do video..
Hi Tejaswi, can you remind me tomorrow.
I will then note it in my todo list and plan it for weekend .
@@codestorywithMIK ok sure sir
@@codestorywithMIK sir u told to remind today about questions video
❤❤❤
Gaddhe? Itne bhi descriptive variables nhi chahiye sir 😹
Ha ha 😅
Will take care of this from next time 🤓😁
@@codestorywithMIK no sir I was jk. -Daag- Descriptive variables ache h
@tappebajgamingmaudaha3051 share your code bhai. Java ya c++ ?
@@xiaoshen194 Daag ache hain
why i am getting TLE
Bhai ek cheez puchni thi ... Agar meri cp ki profile achi nahi hn toh kya offcampus possible nahi hn ....although I have been doing leetcode with streak of 224 day .
No it’s not mandatory.
But always ensure that whatever you study, ensure to understand it thoroughly, understand multiple ways to approach a problem.
I have seen many people who didn’t do cp but they landed in very good places.
But one thing to note that the competition has increased a lot and that’s why many companies sometimes ask cp level qns in OAs.
It can be asked because of two reasons :
1) They see strong competition and they want to filter applicants
2) Their vacancies are filled and now they don’t want to hire more people and hence only few are able to cope up with cp.
But i still suggest everyone to FIRST BUILD YOUR CONCEPTS IN DS TOPICS to a good depth and then move to solving easy, then medium and then hard qns and then cp level qns if time permits
@@codestorywithMIK dhanyawad bhai 🥰
Brother are you available at tonight for an 15 min 1-1 session on topmate.
Sorry Deepti,
Actually i have not been able to take topmate sessions as I am travelling abroad for 3 months from this month.
I will be available soon on that ❤️❤️❤️
@@codestorywithMIK whenever free please guide me..i am struggling brother.