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

ความคิดเห็น • 119

  • @nitisharma8973
    @nitisharma8973 ปีที่แล้ว +12

    Thanks!

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +3

      Thank you for such a nice gesture 😊

    • @user-ub2is4rs4x
      @user-ub2is4rs4x 4 หลายเดือนก่อน

      😮

    • @jeevan-23
      @jeevan-23 11 ชั่วโมงที่ผ่านมา

      @@user-ub2is4rs4x she has contributed so many times

  • @sachinmohanty4577
    @sachinmohanty4577 ปีที่แล้ว +29

    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 ❤

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +27

      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 ❤️❤️❤️

    • @MounikaEMB
      @MounikaEMB ปีที่แล้ว +1

      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 🙏🙏

    • @ugcwithaddi
      @ugcwithaddi ปีที่แล้ว

      The unsung hero.
      People will soon find this legend

    • @souravjoshi2293
      @souravjoshi2293 ปีที่แล้ว

      We are with you MIK.
      Your efforts have not gone unnoticed. I feel bad for those who are not aware of your channel.

    • @AlishaKhan-ww3io
      @AlishaKhan-ww3io ปีที่แล้ว

      king of DSA

  • @codestorywithMIK
    @codestorywithMIK  ปีที่แล้ว +9

    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

    • @karnikasingh9140
      @karnikasingh9140 ปีที่แล้ว

      this java solution gives TLE is that just with me ?

  • @twi4458
    @twi4458 ปีที่แล้ว +2

    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.

  • @wearevacationuncoverers
    @wearevacationuncoverers ปีที่แล้ว +2

    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.

  • @Ankitkumar-fz3kc
    @Ankitkumar-fz3kc ปีที่แล้ว +3

    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.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Means a lot 😇❤️🙏

    • @Ankitkumar-fz3kc
      @Ankitkumar-fz3kc ปีที่แล้ว +1

      @@codestorywithMIK Anything apart from TH-cam to get mentorship by you??

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      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 .

    • @Ankitkumar-fz3kc
      @Ankitkumar-fz3kc ปีที่แล้ว

      @@codestorywithMIK Okay thanks for the hardwork you are putting for us , will always be grateful for this.

  • @rahulmaurya6451
    @rahulmaurya6451 ปีที่แล้ว +3

    Can't get more cleaner code than this,, We are very grateful having you as Our mentor..
    Proud to be your subscriber 🙏

  • @ITISHJAIN-s1p
    @ITISHJAIN-s1p 22 วันที่ผ่านมา +1

    bhai bohot pyara explanation hai pura bohot acche se samajh aaya , really good work man !!

  • @percyx29
    @percyx29 ปีที่แล้ว +3

    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!

  • @GeniusOG
    @GeniusOG ปีที่แล้ว +3

    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;
    }
    }

  • @HolidayHungry
    @HolidayHungry 6 หลายเดือนก่อน +3

    Just "gaddha" is enough to recall this problem 😁
    Thanks for the simple explanation Mazhar.

  • @aadil4236
    @aadil4236 ปีที่แล้ว +3

    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!

  • @tejaspatel2212
    @tejaspatel2212 ปีที่แล้ว +2

    Awesome video! Was seeing your videos since you have less than 1k subscribers! Really happy to see you grow 🤩

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Means a lot.
      Thank you so much for staying since the beginning ❤️

  • @beinghappy9223
    @beinghappy9223 ปีที่แล้ว +5

    Roz video kholo , "Isme Medium/Hard marked hain but actually yeh question kaafi easy hain "

  • @anuppatankar4294
    @anuppatankar4294 ปีที่แล้ว +3

    As Always Best Explanation 🔥

  • @shoaibakhtar9194
    @shoaibakhtar9194 7 หลายเดือนก่อน +1

    Couldn't be more simpler than this. Love your content.

  • @_AMIT-ji4gy
    @_AMIT-ji4gy ปีที่แล้ว +1

    recently i started to watch your video ,and your explanations are simple .👌

  • @tutuimam3381
    @tutuimam3381 ปีที่แล้ว +4

    Thanks a lot

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 ปีที่แล้ว +1

    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 ❤🎉

    • @wearevacationuncoverers
      @wearevacationuncoverers ปีที่แล้ว

      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.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Glad I could help ❤️❤️

  • @AlishaKhan-ww3io
    @AlishaKhan-ww3io ปีที่แล้ว +1

    you are simply the best

  • @alokgautam02
    @alokgautam02 ปีที่แล้ว +2

    thnx for the detailed soln.😇

  • @rabeakhatun2819
    @rabeakhatun2819 ปีที่แล้ว +1

    Crystal Clear 💎

  • @Dettol_Vodka
    @Dettol_Vodka ปีที่แล้ว +1

    Did this question on my own, although it took 2 hours to implement the whole approach.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      So glad you implemented it on your own 💪

  • @phoddaal7130
    @phoddaal7130 ปีที่แล้ว +2

    i was close to the approach but found implementaion to be typical

  • @adarshdhital007
    @adarshdhital007 ปีที่แล้ว +1

    Nice video and perfect explanation as always for all the problems....

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thank you ❤️😇

    • @deeptiranjan2005
      @deeptiranjan2005 ปีที่แล้ว

      @@codestorywithMIK Brother are you available at tonight for an 15 min 1-1 session on topmate.

  • @aadil4236
    @aadil4236 ปีที่แล้ว +2

    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.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      I totally agree.
      Qns like these improve our ability to write clean and understandable code.
      Sure thing, i will share more

    • @souravjoshi2293
      @souravjoshi2293 ปีที่แล้ว

      correct

  • @EatCodeAndSleep
    @EatCodeAndSleep ปีที่แล้ว +1

    Thanks a lot that was so helpfull

  • @shadabkalim9102
    @shadabkalim9102 ปีที่แล้ว +1

    Exact same asked in Intuit oa yesterday hope I watched this vid earlier

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thank you for sharing this ❤️❤️❤️

  • @sumitbaghel6203
    @sumitbaghel6203 ปีที่แล้ว +1

    Maza aa gaya. Thanks❤

  • @turing_machine544
    @turing_machine544 ปีที่แล้ว +1

    I got this problem in "Hudson River Trading" company OA.

  • @ishwarkoki1119
    @ishwarkoki1119 ปีที่แล้ว +2

    First time I saw mik dislike a question and I can understand why !

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +2

      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

    • @ishwarkoki1119
      @ishwarkoki1119 ปีที่แล้ว

      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.

  • @souvikmukherjee8245
    @souvikmukherjee8245 ปีที่แล้ว +4

    Space : ❌
    Gaddha : ✅

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +3

      😁😁
      It reminds me of Drake meme 🤓

    • @souvikmukherjee8245
      @souvikmukherjee8245 ปีที่แล้ว +1

      @@codestorywithMIK That was my intention. 😊 Take a look at the meme I shared in the discussion section of this question. 🤣

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Please share the link 😅
      I want to see

    • @souravjoshi2293
      @souravjoshi2293 ปีที่แล้ว

      ha ha sahi hai

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 ปีที่แล้ว +1

    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

  • @gurudassulebhavikar
    @gurudassulebhavikar 8 หลายเดือนก่อน +1

    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.

    • @codestorywithMIK
      @codestorywithMIK  8 หลายเดือนก่อน

      My bad. I will take care from next time to not use such variables.
      Thank you for your kind words 🙏🙏❤️❤️

  • @pankajsuryavanshi8332
    @pankajsuryavanshi8332 ปีที่แล้ว +2

    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 😅

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Means a lot 😇❤️
      Sometimes it gets very difficult to to manage, so squeezing time from other tasks is the only option 😁

    • @souravjoshi2293
      @souravjoshi2293 ปีที่แล้ว

      Same qn 😅

    • @pankajsuryavanshi8332
      @pankajsuryavanshi8332 ปีที่แล้ว

      @@codestorywithMIK please start live video might be that will make mandatory

  • @shivamtomar9658
    @shivamtomar9658 ปีที่แล้ว +1

    Thanks sir

  • @user-oh2gy6re6o
    @user-oh2gy6re6o 6 หลายเดือนก่อน +1

    good yar wowwww

  • @gaurimandot5788
    @gaurimandot5788 11 หลายเดือนก่อน

    Your code was ultra clean.😍

  • @doctorajshorts1590
    @doctorajshorts1590 ปีที่แล้ว +2

    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 :)

  • @harikrushnasuhagiya3925
    @harikrushnasuhagiya3925 ปีที่แล้ว +2

    This belongs inside the while loop, right? cz we want as left as possible;
    if(extra space > 0) {
    s += " ";
    extra space--;
    }

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      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

  • @abc-ym4zs
    @abc-ym4zs ปีที่แล้ว +2

    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

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Hey,
      Do you mean OA qn videos ?

    • @abc-ym4zs
      @abc-ym4zs ปีที่แล้ว +1

      @@codestorywithMIK yes sir

    • @abc-ym4zs
      @abc-ym4zs ปีที่แล้ว +1

      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

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Definitely. Noted on this
      Let me collect OAs and plan soon

    • @abc-ym4zs
      @abc-ym4zs ปีที่แล้ว

      @@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

  • @gaurimandot5788
    @gaurimandot5788 11 หลายเดือนก่อน

    Please launch a DSA course of advance level. I love your teaching sir.

  • @user-oh2gy6re6o
    @user-oh2gy6re6o 6 หลายเดือนก่อน +1

    good good

  • @ece116pranaykumar4
    @ece116pranaykumar4 ปีที่แล้ว +1

    Can you make video on median of two sorted arrays

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Can you please share leetcode link Pranay ?

  • @mycollegeLife.
    @mycollegeLife. 17 วันที่ผ่านมา

    wonderful bro.
    Bhai apni real identity reveal kro.

  • @sincemydivorce7641
    @sincemydivorce7641 ปีที่แล้ว +2

    Nice explanation! However, justify why you disliked the question.😂

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      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 😄

  • @M.m554
    @M.m554 11 หลายเดือนก่อน

    Sir oa wale ques pe video banadoo plzz

  • @user-ub2is4rs4x
    @user-ub2is4rs4x 4 หลายเดือนก่อน

    Yaar itna acha koi kaise parha sakta hai

  • @Tejaswi-xd4re
    @Tejaswi-xd4re ปีที่แล้ว +1

    Sir when will u bring that topic wise questions which to do video..

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Hi Tejaswi, can you remind me tomorrow.
      I will then note it in my todo list and plan it for weekend .

    • @Tejaswi-xd4re
      @Tejaswi-xd4re ปีที่แล้ว

      @@codestorywithMIK ok sure sir

    • @Tejaswi-xd4re
      @Tejaswi-xd4re ปีที่แล้ว

      @@codestorywithMIK sir u told to remind today about questions video

  • @codeandtalk6
    @codeandtalk6 ปีที่แล้ว +1

    ❤❤❤

  • @xiaoshen194
    @xiaoshen194 ปีที่แล้ว +4

    Gaddhe? Itne bhi descriptive variables nhi chahiye sir 😹

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +4

      Ha ha 😅
      Will take care of this from next time 🤓😁

    • @xiaoshen194
      @xiaoshen194 ปีที่แล้ว +2

      @@codestorywithMIK no sir I was jk. -Daag- Descriptive variables ache h

    • @souravjoshi2293
      @souravjoshi2293 ปีที่แล้ว

      @tappebajgamingmaudaha3051 share your code bhai. Java ya c++ ?

    • @Thriftinghai
      @Thriftinghai ปีที่แล้ว

      @@xiaoshen194 Daag ache hain

  • @fejurehman7932
    @fejurehman7932 ปีที่แล้ว

    why i am getting TLE

  • @level_up.1908
    @level_up.1908 ปีที่แล้ว +1

    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 .

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      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

    • @level_up.1908
      @level_up.1908 ปีที่แล้ว

      @@codestorywithMIK dhanyawad bhai 🥰

  • @deeptiranjan2005
    @deeptiranjan2005 ปีที่แล้ว +3

    Brother are you available at tonight for an 15 min 1-1 session on topmate.

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +2

      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 ❤️❤️❤️

    • @deeptiranjan2005
      @deeptiranjan2005 ปีที่แล้ว

      @@codestorywithMIK whenever free please guide me..i am struggling brother.