Google Coding Interview with an ex-Microsoft Software Engineer

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024

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

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

    Hope this was fun to watch as we simulated a real world Interview over Google Hangouts.
    "Going Greedy does result in minimization but it comes at a cost, and that cost is Wrong Answer".
    Part II and other links are in the description.

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

      Do u think in hindi? Or maybe HINGLISH?😂 Because I could catch a few hindi sounding words whenever you just started talking after a pause.😂😂
      Great video by the way, I liked your approach to the problem.
      You should make more videos of this kind!

    • @HarshSharma-po9xt
      @HarshSharma-po9xt 4 ปีที่แล้ว +1

      could you have used the elements of the array to integrate and become the pi string itself...
      If yes what would be it's time complexity...

    • @DipankarDas-pg6zo
      @DipankarDas-pg6zo 4 ปีที่แล้ว +4

      Hi I Have done it python please find the below code :
      def getmaxstr(listar):
      maxsrtr = max(listar, key=len)
      maxsrtlen = len(max(listar, key=len))
      return (maxsrtr,maxsrtlen)

      def main():
      n="3141592653589793238462643383279"
      listar=["314","49","9001","14","9323","8462643383279","4","793","23846264338","15926535897","8462643383279234"]
      listlen = len(listar)
      i =0;
      l=list()
      mainflag=False
      while i < listlen:
      tup=()
      tup = getmaxstr(listar)
      i=i+1
      if len(n) > 0 and len(listar) > 0:
      if tup[0] in n:
      fndpos = n.find(tup[0])
      endlen= int(fndpos) + int(tup[1])
      n = n.replace(n[int(fndpos):endlen],'')
      listar.remove(tup[0])
      l.append(tup[0])
      else:
      listar.remove(tup[0])
      else:
      mainflag=True


      if mainflag:
      break


      for val in l:
      print(val)

      if __name__ == '__main__':
      main()
      Please let me if I can improve that code any other way.
      Thanks,
      Dipu

    • @slowtuber5345
      @slowtuber5345 4 ปีที่แล้ว

      i was going to use the first solution you mentioned
      great video and tips

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

      i can't believe i spent 4 hour on this question, i am using Pyhton to make it work.
      my code:
      PI = "314159265358979323846263383279"
      IN = ['314','49','9001','15926535897','14','9323',
      '846263383279','4','793']
      def findMatch(a,b):
      index = []
      pos_a = 0
      count_match = 0
      for i in range(0, len(b)):
      if pos_a >= len(a):
      break
      if checkStr(a,pos_a,b,i) == True:
      pos_a += len(b[i])
      count_match+=1
      index.append(b[i])
      else:
      pos_a = pos_a
      return f"{count_match-1}({' '.join(index)})"
      def checkStr(strA,pos_a,listB,pos_b):
      for i in range(0, len(listB[pos_b])):
      if strA[pos_a+i] != listB[pos_b][i]:
      return False
      else:
      return True
      print(findMatch(PI,IN))
      I think I am fail the interview.

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

    How many other people think doing coding interview questions is fun like Rachit and I? 😂

    • @sarathkumar-ie5iu
      @sarathkumar-ie5iu 5 ปีที่แล้ว +6

      Is algoexpert videos down?

    • @SumitKumar-fn3gj
      @SumitKumar-fn3gj 5 ปีที่แล้ว +1

      Me

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

      @@vidhubhardwaj9672 I've got a complicated last name, that's for sure! 😛And awesome; glad you like it!

    • @SumitKumar-pj9uo
      @SumitKumar-pj9uo 5 ปีที่แล้ว

      @@SumitKumar-fn3gj Me too

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

      @@clem man i work in jp morgan usa, i m an indian

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

    I have 0 coding ability/experience, and I have no idea what they are talking about. Why am I watching this?!

  • @abhisheksharma-ud8mz
    @abhisheksharma-ud8mz 4 ปีที่แล้ว +21

    i remember giving interview at adobe and totally changing my code at the last while writing. It is always good to be interactive while writing code. Thanks Rachit.

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

    you must be that guy who does all the work in a group project damn.

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

    I thought coding interview only caused me to talk weirdly. Now I feel better

  • @AdityaKumar-pb4lr
    @AdityaKumar-pb4lr 4 ปีที่แล้ว +320

    i just learnt how to write hello world in c and now this video is recommended to me.
    😑😑

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

      learn c#

    • @AdityaKumar-pb4lr
      @AdityaKumar-pb4lr 4 ปีที่แล้ว +4

      C# microsoft version of java😂😂

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

      @@AdityaKumar-pb4lr c# BETTER version of java :)
      edit: please stop replying to this. this information is false and only for entertainment purposes. still c# is most of the time better than java as a language

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

      I only know HTMl🤣

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

      Sujan Basak lets hack nasa together

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

    I was asked the exact same question in the final round for SDE-2 role at Amazon. No price for guessing I was rejected ;)

    • @saketpatil1306
      @saketpatil1306 3 ปีที่แล้ว

      Hey, I'll be entering college in few months, can I please ask you some doubts 🙏

    • @Levelord92
      @Levelord92 2 ปีที่แล้ว

      what about now bro? Did you get a job?

    • @mymoviemania1
      @mymoviemania1 2 ปีที่แล้ว

      @@saketpatil1306 what?

    • @saketpatil1306
      @saketpatil1306 2 ปีที่แล้ว

      @@mymoviemania1 are u in cs engineering? I wanted to ask something

    • @mymoviemania1
      @mymoviemania1 2 ปีที่แล้ว

      @@saketpatil1306 will be in a few days. Yet u can i ask what u want to knlw

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

    1:55 Why did Anjali cancel your order? How dare she? haha

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

    getting to a solution this fast needs a great level of practice. Well Done Rachit.

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

      Thanks

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

      @@bulletprooftrading if u practise well, u'll get it in prob 2-3 months

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

      @@bulletprooftrading no way. I would think at least a year of learning.

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

      @@bhanupratapsinghrajawat3686 maybe if you're Einstein, but we all normal folks need years

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

    No of "Basically" used by rachit in video is 47 damn high basically😂

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

      man, youu have so much free time.

    • @tanzeelgeelani9678
      @tanzeelgeelani9678 3 ปีที่แล้ว

      @@tapankumarbaral1244 what????.

    • @vineethsai1575
      @vineethsai1575 3 ปีที่แล้ว

      It's a problem with mostly all indians. Use of the words like "Basically", "OK" etc.

    • @aj9706
      @aj9706 2 ปีที่แล้ว

      @@vineethsai1575 it doesn't matter success matters

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

    love to see how whole YT community helping each other with such collabs

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

    Really nice interaction. Also i think this problem is same as word break O(n^2), chao.

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

      Wow great insight!

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

      Yes, that's the first thought came in my mind, it's a word break just with numbers.

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

    This is my initial reaction to the problem i paused the video at 5:20 and did not watch further. This can be solved with simple DP using O(n) space for the DP 1d array and probably a hash map DS to store the favourite digit sequences (for a O(1) lookup while doing the memoisation), the time complexity would be O(n2) worst case but should be Amortised better than this for random inputs. The algo is as follows, Lets maintain a DP 1d array 'A' this would have any value between -1 to n (where 'n' is length of the input string 'B' ), the value -1 of A[i] indicates there is no possible favourable split of input string B[0...i], but any value A[i] greater than -1 and less than 'n' indicates there is a fvourable split and it denotes the immediate previous index of string 'B' which has the space, so essentially the problem boils down to A[n-1] having any value > -1 then we have a favourable split of string else its not possible, to identify the positions of spaces we just traverse back from A[n-1] to get all indices which has the space. The memoization formula would be A[i] = { for all j , 0 =0 &&

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

      looks like you are genius

    • @perc-ai
      @perc-ai 5 ปีที่แล้ว

      haha damn you must be a sr software engineer

    • @souravraychaudhuri6600
      @souravraychaudhuri6600 5 ปีที่แล้ว

      I had thought of the exact same solution.

    • @Blahrg
      @Blahrg 4 ปีที่แล้ว

      I am not that good at programming and i am still learning. Can you explain what is the need of the array to keep track of things? Why can't we have a hash containing the prefered strings and then create a string 1 character at a time from the input array and if the charcter exists increment a count and reset the checking string and start a new string from where it was left off:
      for(i=1; i count++; cur=" "
      wouldn't that be O(n) as well?

    • @abhishek.rathore
      @abhishek.rathore 4 ปีที่แล้ว +1

      @@Blahrg Yeah but that does not minimises spaces.

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

    There's a minor improvement you can do to improve that solution as well. Instead of using an unordered map for storing the favorite strings, you could use a trie instead. Maintain two variables for each trie node, one which stores the list of next pointers from the current node and the other, a boolean variable which tells whether the prefix denoted by the path from the sentinel node to the current node is one of the favorite strings. The checking part is straightforward after that. The time complexity will still be O(n*max_length(favString)) theoretically, but in practice, it'll be much faster than an unordered map based solution because unordered maps have a huge constant factor, which might even be worse than an ordered map based solution sometimes.

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

      that's happen when a iitian does hardcore competetive programming for just get an faang india offer🤣🤣🤣🤣🤣🤣

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

    I used to think myself as a good programmer before i watched this

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

      Look up set theory. Could help

    • @PoulJulle-wb9iu
      @PoulJulle-wb9iu 4 ปีที่แล้ว +2

      @@regd9297 why

    • @JamesSmith-cm7sg
      @JamesSmith-cm7sg 4 ปีที่แล้ว +2

      This is just one area of programming.

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

      Haha.Welcome to the world of dynamic programming.I' m not going to welcome myself there anyways because I finally found that its not my cup of tea.

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

    12:45 he was dreaming dude!!!

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

    Thing I learned from this video is to make an interactive interview session, Interviewer should be that much supportive. Please bring such topics which really gives feeling of giving interview with sense of thinking that needs to be followed by candidate while giving interviews.

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

    Hey Rachit,
    I owe you a lot for my learning weekends.
    Thanks a ton!! :)

  • @HemanthHR-fi5rq
    @HemanthHR-fi5rq 4 ปีที่แล้ว +148

    I am an Computer science engineer and I literally have no idea what they are talking about!like who are in same position!

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

      Im mechanical engineer almost understood everything.

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

      I think coding is simple but you need some basic skills to use mathematics. And practice

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

      Im a class 12 student and even I can do this problem that too in 3 languages

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

      I'm 5 years old and i solved this problem in 2 milliseconds you guys are stoopid

    • @HemanthHR-fi5rq
      @HemanthHR-fi5rq 4 ปีที่แล้ว +6

      @@theendurance Yeah kiddo I know that I'm stupid thanks for letting me know it.,😄✌️

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

    Why they are talking in alien language

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

    Good, but.. both seem confused on what the program is supposed to do. In development, clarity (ie someone can come in, read the code, and understand straight away) and modularization (code re-use, organize code efficiently as possible) are two of the most important things, the naming of the variables is a huge minus for clarity. The communication between them is clearly lacking. Also, what about test inputs and walking through the code and seeing if it worked? What about malformed test inputs? etc etc..

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

    Google interview in a apple mac by an ex Microsoft guy😂
    Chronology samaj rahe hai ap!

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

      Hahahahahahahaha......

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

      Anurag Srivastava LoL that meme 😂

    • @rishabh7011
      @rishabh7011 4 ปีที่แล้ว

      🤣🤣🤣🤣🤣

    • @data_analyst7944
      @data_analyst7944 4 ปีที่แล้ว

      Yeh chronology SE zyada trilogy lag rahi hai

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

      On youtube

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

    The code written in the video is logically incorrect and never solves the problem. In a real Google interview the interviewer is gonna give a thumbs down.
    FYI, the problem is similar to 'Word Break' in Leetcode.

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

    Rachit you are doing a great job your videos are very helpful. please make videos on how to get internship in companies like microsoft,google ,goldmansachs etc from offcampus. What are the process ,what are there expectations from interns ,how there resume should look like..

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

    So basically you do dynamic programming where you mark the end of substrings that occur in your hash_set of numbers, and then only start trying to build new strings from the character right after the old one. And then you cache the minimum breaks that were needed to get to a particular point.

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

    I can done it with recursive ,, calling check thrive

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

    Wow. I actually did the first question with backtracking. I an 5 mins in the videos, I think i found the solution. It's awesome that I started working on competitive programming 45 days ago.its word break problem from leetcode

    • @karthikmucheli7930
      @karthikmucheli7930 5 ปีที่แล้ว

      @Lokesh Nimawat the best is to get better algorithms and data structures.

    • @hmmmm4193
      @hmmmm4193 5 ปีที่แล้ว

      @@karthikmucheli7930 which site you prefer for c.p.

    • @karthikmucheli7930
      @karthikmucheli7930 5 ปีที่แล้ว

      @@hmmmm4193 leetcode

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

    For a second I thought it was Ex-Google TeahLead. Damn.

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

      Ex Google, Ex Facebook*

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

      @@adityapaithon6499 Ex Husband too. :D Sad, but he makes it somehow funny.

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

      This thread is all I needed for the day 💞🤣

    • @mohimuddin3770
      @mohimuddin3770 4 ปีที่แล้ว

      @@karthikmucheli7930 😂😂😂

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

    I'm a CRUD boy, I don't need to deal with such problem, lol

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

    Rachit: ”I’m an ex Microsoft employe.”
    My head: ”Hello, welcome to Microsoft tech-support. How can I help you?”

    • @void.xerinium
      @void.xerinium 4 ปีที่แล้ว +5

      re employ me lel

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

      Well ,he is Indian so possibilities are endless.

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

      I get what you did there 😂😂😂

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

      He said he is engineer

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

      Not cool. We educate ourselves and help others too... I get it u were joking... Funny... But not cool, Jus' saying
      Have a good day.

  • @aiswaryajami2841
    @aiswaryajami2841 3 ปีที่แล้ว

    Since the question is asking for minimum number of spaces which is a minimization problem, we could maximize the substrings resulted by introducing spaces to given input string. Sort fav numbers array in decreasing length, check if largest number is a substring of input string. if yes, increment spacesTaken by 1 and now check if 2nd largest number is present in the input string. if yes, introduce space, else continue; .. if entire input string got split into substrings (base case where i reaches n-1) by greedy method of picking largest substring at each iteration , then in this way we could guarantee that spacesTaken will guaranteed to be minimum out of all possible answers. We could use rabin-karp style substring matching for efficient checks. I hope @Rachit/Clement would notice this comment and reply if my algo would work.

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

    I had an Online Coding round like this for DE Shaw and I remember changing my code to cover all the edge cases.

    • @VY-zt3ph
      @VY-zt3ph 3 ปีที่แล้ว

      Did you got selected??

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

      @@VY-zt3ph did you *get*

    • @VY-zt3ph
      @VY-zt3ph 3 ปีที่แล้ว

      @@chiragsharmaTH-cam bro thanks for correcting. But kya karein aadat se majboor hain. Even my gf always pinch me for these mistakes.

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

      @@VY-zt3ph glad ur gf is an expert in this.

    • @VY-zt3ph
      @VY-zt3ph 2 ปีที่แล้ว

      @@rtxmax8223 ab breakup ho gya

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

    Again Quaility content from this channel Thanks a lot

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

    Have no idea what I just watched but it was interesting

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

    I would take a recursive approach using substring. As we need minimum splits ...will sort my list desc and use larger to smaller strings. If at the end of recursion if find remainders ...then that's not a solution and if I did not ....there's is your solution...👍 Rachit approach need lot of index management that makes code vulnerable to crash at few test cases ...

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

    Wow so complex question and algo!!
    Finding the minimum number of spaces, my approach will be with java.1.8
    For every string in fav number array just check if substring is present or not! Increment counter if present! That's it! 🤷‍♂️
    But I'm a newbie! Sorry
    //assuming favArray and string input
    Int spaces = 0;
    for(string token : favArray)
    {
    if(input.contains(token))
    Spaces ++;
    }
    Sysout(spaces) ;

    • @kavyak9700
      @kavyak9700 3 ปีที่แล้ว

      Was thinking same, I don't know c++. So & this symbol was difficult for me understand.
      Yes we have contains in Java and that should solve it easily

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

    Using a hash-table?
    for every term in the favArr, return a key/value pair = startIndex: startIndex+termLength. These pairs form a hash-table.
    Check the Big String from index 0, if there is no key in the hash-table match 0, then it is not possible to split the Big String, return Infinite. Otherwise, find all keys which match 0,
    for each matched key,
    if the value > N, then it has no valid split, return Infinite
    if the value == N, then return 0
    if the value < N, then return 1 + ( repeat the process by check start from the value to N )
    return the min of all results from keys
    Big String=3141592389657302, length = N = 16
    favArr = ['3', '314', '15923', '4', '793', '896', '302', '89657', '7302', '896573024']
    -> hash-table:
    {0:1, 0:3, 3:8, 2:3, -1:2, 8:11, 13:16, 8:13, 12:16, 8:17}
    minSplit(start=0,N=16)
    = min( 0:1-->1+minSPlit(start=1,N=16), 0:3-->1+minSplit(start=3,N=16) )
    minSplit(s=1,N) = Infinite
    minSplit(s=3,N) = min( 3:8-->1+minSPlit(s=8,N) )
    minSplit(s=8,N) = min( 8:11-->1+minSplit(s=11,N), 8:13-->1+min(s=13,N), 8:17-->Infinite )
    minSplit(s=11,N) = Infinite
    minSplit(s=13, N) = min ( 13:16=N-->0 )
    =>
    minSplit(s=8, N) = 1
    =>
    minSplit(s=3,N)=2
    =>
    minSplit(s=0,N)=3
    -------- Note: When Big String has repeated numbers/patterns (not like Pi), then have to be careful to get the startIndex of each term in the favArr, instead of as simple as indexOf(term), should use BigString.indexOf(term, lastFoundIndex+1). for example, Big String = 2222, favArr=[2, 2, 22, 222, 22222]....

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

    Probably a typo here:
    if (ans == UNDEFINED) return ans;

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

      Yeah thanks.

    • @i-am-mkv
      @i-am-mkv 4 ปีที่แล้ว +4

      Read the comments just to find this comment. :)

    • @amritnalam9994
      @amritnalam9994 4 ปีที่แล้ว

      What's the typo here?

    • @saijayavinothtvs2588
      @saijayavinothtvs2588 3 ปีที่แล้ว

      Also, I think, in addition to returning the answer, he should also store the ans in that dp array...

  • @patrickatienza7329
    @patrickatienza7329 5 ปีที่แล้ว

    Using trie would have a time complexity of O (N*K + M) where N is the number of strings in the array, K is the average length of each string, and M is the length of the main string. The space complexity is O (N).

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

    We can insert all the favourtie strings into a "Trie" data structure. And then while we pass thru the large string, we can check if that partial string exists in trie. If it exists, break it up.

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

    Pie = 3.14blablabla
    thanks for the info, I can use this in tomorrows math test. I am sure that I will get A+ grade. Thanks once again.

  • @ash-code
    @ash-code 5 ปีที่แล้ว +2

    Can't this be done with
    1. Needle in haystack comparison of the strings in the list with the big string. O(m x n) - Can be linear time if using KMP algorithm O(n+m).
    2. Get the start and end indexes and create a dependency map - Memory is O(m)
    3. Traverse the dependency map with DFS and notate the min steps to reach the end index in the dependency map. The min step is the min space. Time is O(m)
    O(n+m) + O(m). Rachit would be interested in knowing what you think. Thanks!

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

    Great collaboration...i saw algo expert and it is something that i need the most... thanks...

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

    this is a straightforward dynamic programming problem: partition a string such that all partitioned substrings are in some allowable list of strings. this guy needs to practice how to recognize when a problem has recursive structure

    • @PoulJulle-wb9iu
      @PoulJulle-wb9iu 4 ปีที่แล้ว +1

      recursion is for fking noobs....

    • @James-yz4cc
      @James-yz4cc 4 ปีที่แล้ว

      @@PoulJulle-wb9iu Nope.

    • @James-yz4cc
      @James-yz4cc 4 ปีที่แล้ว +4

      ​@@PoulJulle-wb9iu The basic solution is you put every word in a hash map and each time you see a match, you either take the word and continue with the rest of the string or without taking any string and moving on. You either take it or not. This then becomes like a 0/1 structure and you can do dp to avoid unnecessary repetion.
      In short, learn before you dare to talk like a boss.

    • @James-yz4cc
      @James-yz4cc 4 ปีที่แล้ว +6

      @@PoulJulle-wb9iu The solution provided in this video *IS* a recursive solution. To improve time complexity it uses an array to store calculated result. This is not actually DP but memoization. Most people dont know that. The essence of memoization is still recursion. DP does not have recursive calls.

    • @PoulJulle-wb9iu
      @PoulJulle-wb9iu 4 ปีที่แล้ว +1

      @@James-yz4cc DP does not have recursive calls? man, you are just a school boy, who were taught wrongly and didnt think. or why are you saying nonsense. DP can both be iterative or recursive, obviously

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

    Thanks for the great mock interview!

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

    aight, imma head out.

  • @chamarakv98madushanka41
    @chamarakv98madushanka41 4 ปีที่แล้ว

    This is great great...Just motivated by watching a real programmer's coding. Today I got to know how programmers solving problems and how they are coding and about the steps also. Thank you soo much.lv ya.

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

    I was waiting up on you to take care of that -1 part which you obviously did in the end. I think you even made a vid earlier on this type of question.

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

    man now i am also becoming pro in python, i have successfully done hello world

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

    Awesome video, well done!

  • @Slayer-ns3ge
    @Slayer-ns3ge 4 ปีที่แล้ว +18

    Damn understanding that question will take me 45 minute and when to solve it lmao 🤣🤣🤣🤣

  • @Nikhil-cj7rn
    @Nikhil-cj7rn 4 ปีที่แล้ว

    Loved your channel keep this good work going...hats of man

  • @guangyangche1655
    @guangyangche1655 4 ปีที่แล้ว

    I think it's a very typical DP problem which can be solved in O(n^2) time am i right. Iike set opt(i) as belows: first we will maintain an array called M(2, n) and every column of M is for every character in the string. if we go through the string, we stop at i and want to see if we can add a space after s[i], so s[0-i] will be divided into several correctly. We go to the first place we can add space, which is the head of the string and check if s[0-i] is in the dictionary, if yes we will make M[i][0] = 1, M[i][1]= -1, otherwise we move to next j position and M[j][0] is 1. We check if s[j+1 - i] is in the dictionary, if yes then make M[i][0] = 1, M[i][1]= j, if not, we move on to next j position whose M[j][0] is 1...... Once we find a good j we stop the process for i position and move one step forward, unless we make M[i][0]=-1. After n^2 time we can get the M array and we can answer the question through this M.

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

    Nice video Rachit.
    loved this channel, specially solving coding questions like this, like Codejam-problems, specifically, I liked your solution on "Decryption Problem".
    BTW, Are you giving Google's Codejam tomorrow?
    if yes then all the best Rachit.
    :)

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

    Ah it’s sorting the favorites list order by string length.. and do a for loop match with exist and add a space...

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

      no. what about "abcde" and [ab,abc,cde,d,e]. you will check first abc and then add d and e, and the best solution will be ab cde.

  • @dongfangsun2250
    @dongfangsun2250 4 ปีที่แล้ว

    Python solution
    def countSpace(string, targets):
    targets_set = set(targets)
    dp = [0] + [float('inf') for i in range(len(string))]
    for i in range(1, len(string) + 1):
    MIN = float('inf')
    for j in range(0, i):
    if string[j:i] in targets_set:
    MIN = min(MIN, dp[j])
    dp[i] = MIN + 1
    return dp[-1]

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

    The condition to check whether we have already calculated for the position should be if(ans !=undefined) returns ans

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

    I have been coding for a couple years and let me tell y’all something: if you are not able to find the solution it does NOT mean you are a bad developer. It really does not mean anything, besides one thing: You didn’t practice those type of questions (leet Code style).
    If you Leetcode or do another similar activity you will FOR SURE get better and start to get the hang. Does it help you though in your everyday work as developer? Probably not.

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

    Loved the idea of doing mock interviews for Big Companies. Really helpful. Please keep doing it for other companies also. Thanks.

  • @akshayagarwal2714
    @akshayagarwal2714 4 ปีที่แล้ว

    Shouldn't the "ans" check be like
    if( ans != UNDEFINED ) return ans; it should be a NOT EQUAL TO
    Since when ans == UNDEFINED it means that this dp[pos] hasn't been calculated yet, it isn't initialized with the other -1 or permissible index. Hence it should move forward to the loop instead of return there itself.
    With ( ans != undefined ) we will be saying that it already has some cached solution (-1 or index ) hence we should return the answer.
    Give this a thought and please correct me if I am wrong.

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

    Awesome video Rachit bro.. thanks.. it's helping a lot

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

    I was hoping he was going to answer the question 😒

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

    I dont think the answer works because when you reach N = 0 you return 0, then take the min which will always be 0 after all recursive calls end.

  • @jay-rathod-01
    @jay-rathod-01 3 ปีที่แล้ว +2

    Clement should be interviewee sometimes too. It would be a lot of fun.🤗

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

    Meanwhile white hat junior chintu op 😂

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

    Holy fucking god you are really good. The reason why you got in Microsoft.

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

      Hahaha thanks

    • @subhajitdas2784
      @subhajitdas2784 5 ปีที่แล้ว

      @@RachitJain I just finished watching part 2. Dammmmm you are good.

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

      Lol thanks again

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

    Can you please make a separate video explaining the detailed analysis on time complexity of this solution.

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

    The DP array was supposed to be populated within the function. @Clement missed it, but good walkthrough overall.

  • @dipanshparmar3769
    @dipanshparmar3769 4 ปีที่แล้ว

    Can't we just do it like this:
    def countSpace(string, llist):
    spaceCount = 0
    for i in llist:
    if i in string:
    spaceCount += 1
    return spaceCount - 1
    that if we find that list element in the provided string we will simply increase the space count by 1 each time we find the element in provided string.

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

    I would cut the string off whenever the longest string is found in the pi. Pass the new pi and new fav string for recursive call till the pi is empty or no fav string in pi. The run time is probably high. So far is what I think. Maybe a better way. Please share.

    • @Vattevaii
      @Vattevaii 4 ปีที่แล้ว

      Finding right positions of the cut off part may be impossible here

    • @ashethebostonterrier4918
      @ashethebostonterrier4918 4 ปีที่แล้ว

      Vatte Vaii i am thinking using a map with position as their key since the index is fixed.

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

    We can do it in better complexity by using aho corasick algorithm. This will give time complexity of O(n + m).

  • @akshatsahu8021
    @akshatsahu8021 3 ปีที่แล้ว

    Thanks dude. your way of thinking helped me learn a lot !!

  • @triton6771
    @triton6771 3 ปีที่แล้ว

    I'm not pro at algos but off the top of my head I'll use a sliding window to check through the string and get minimal substrings found in the array. It'll be o (n) too

  • @ARUNABHPRIYADARSHI
    @ARUNABHPRIYADARSHI 4 ปีที่แล้ว

    i have an idea, instead of using top down approach used by rachit we can have bottom up approach, which goes like this:
    * find the first number in pie
    * find the numbers in fav array which start with that number
    * suppose we have more than one, we go over them iteratively and marks them as used
    * now we check , if the number choosen in fav array, are in same sequence as in the pie number,
    -> if does we find the next number and start iterating from step 2,
    for example, 34684654684684 is pie
    and fav array contains 346, 35
    346 has same number as the pie initials, so we start iterating from 84654684684
    -> if it doesn't we go to next number in the iterations
    * go on till we came to the end of the number
    does it make any sense, if it doesn't please comment below and I would love to clear it up.
    I would love to know if you guys find any flaw in it.

  • @salonisharma9479
    @salonisharma9479 4 ปีที่แล้ว

    Something that doesn't blufff....i heard the question, and Subscribed. That's really what interview is 👏👏

  • @ritzchaudhury9448
    @ritzchaudhury9448 4 ปีที่แล้ว

    How about using probability to find out the maximum number of same digit numbers for.. and then just code it to find the number of spaces we need.
    example:- if we have three, 3 digit numbers in the favorite array out of 5, then the probability would be 3/5.
    which is more than 50%. So here we go

  • @ryuu.5054
    @ryuu.5054 4 ปีที่แล้ว +18

    I want to be a software engineer and after that video i getting afraid of the interview. If they ask me like this what can i do?
    ....just cry 😢

    • @okey1317
      @okey1317 4 ปีที่แล้ว

      hehe

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

      me too :(

    • @HT-on5sk
      @HT-on5sk 4 ปีที่แล้ว +5

      Get up, shake the interview's hand, thank him for taking the time to see you, and then walk out the room without saying a single word.

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

    This is a really interesting question... Gonna search if this question is on any coding platforms.. thanks for the question Clement and Rachit

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

      search for 'word break', the code given in the video is not even close to be able to compile and will most likely to fail in a real google interview, to be honest

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

    Store your favorite list in Trie Data Structure.
    Create 2 variables, say I and J.
    Use point I to irerate over each character of the string, and use J to crawl in Trie.
    As soon as J reaches to end of word then store that as result and reset J to root of your Trie.
    Overall Time Complexity:
    Building trie + Iterating over string characters.
    O(W + N)
    N is length of string
    W is number of words in favorite list
    Space Complexity: (Trie)
    O(W)
    W is number of words in favorite list

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

      Nope, in case you have: '31', '41', '5' and '3', '1415'. Your code will choose three elements instead of two, so you will not minimize spaces

  • @rahulchawla6818
    @rahulchawla6818 4 ปีที่แล้ว

    hey so couldn't this question be solved by
    1. arranging the list of fav numbers from largest to smallest
    2.then checking if the first number is present in the number of pi.
    3.if present then checking if there is any space between the number present in pi
    4.if space is present we do nothing
    5.if space is not present we add space on the start and end of the number in pi
    6.then doing the same with other numbers in the fav number list

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

    Honestly I thought this was kinda bad and not a very realistic example. The interviewee, while it's ok to be confident, it's better to be a bit more humble and ask what the interviewer thinks as you go along rather than forcing your answer in. This felt more like the interviewee was saying everything they were doing was right and wasn't being collaborative at all. Sure, they might be competent, but I wouldn't want to work with them.

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

      Thanks for sharing your thoughts, I try to not give off such an impression. I keep sure that I move forward from each step only when I get a green signal from the interviewer, which I think I did.

    • @dhruvvprakash
      @dhruvvprakash 4 ปีที่แล้ว

      Jacob Barr the interviewer would have stopped him to say if something wasn't ok. Nobody needs you sitting on your high horse preaching your own moral standpoint on something so trivial as this. You don't even know the guy in real life and just because his attitude seems a bit over the top based on your highly stringent moral requirements you're going to make a concluding judgement on him? I'm more worried about your attitude now than his.

  • @mayanksharma9454
    @mayanksharma9454 4 ปีที่แล้ว

    Hi Rachit,
    I have a doubt about your solution.
    Lets take this sample case(i have cut the lenght of Pi to make it bit more simple)
    Sample Input:-
    pi = 31415926535
    favourite_words = [314,31415926,15926,535]
    I think as per your given approach the result will give 3 as the minimum space required
    but we can do that in 2 spaces as a minimum.
    Please can u or anyone explain

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

    I think it can be more optimized by using index and mapping

  • @weizhou7070
    @weizhou7070 4 ปีที่แล้ว

    First of all, thank you for the video! Well done!
    The greedy method is purely wrong, *not only* because it may even fail to find any valid answer. It can, in fact, give a non-optimal result too.
    Consider S=3141592653589793, Fav=[3141592, 653, 589, 793, 314, 1592653589793].
    Obviously, the optimal answer is 1 (by using 314 and 1592653589793), but the greedy way will find 3 (using 3141592, 653, 589, 793)

    • @RachitJain
      @RachitJain  4 ปีที่แล้ว

      Yeah, greedy one is wrong - that's what I also tell in the video.

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

    Thank for creating close to real senario..... very soon I realised -> I can not be a Google engineering!.😂😂

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

    I am wondering🤔💭 when will I become experts like you guys....?

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

    I just completed with C and Don't know what to do next, Anyone please help me Which language should I go for next?

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

      49-COMP A -Aakash Gupta C++ would be your best bet if your going into computer science, but any high level object oriented language would suit you, like Java. I’d recommend C++ over it though since it’s basically a higher level version of C.

    • @aakashgupta4428
      @aakashgupta4428 4 ปีที่แล้ว

      @@ramonriddler228 thank you so much, I will be getting started with C++

    • @kelvinxg6754
      @kelvinxg6754 2 ปีที่แล้ว

      Python

  • @yadav-vikas
    @yadav-vikas 5 ปีที่แล้ว +1

    Q. U have 2 strings as input , you have to check which string is greater but u can't use their ASCII value.
    Example -- XYZ and XZ
    It should return XZ as the greater string.( This is quit lexicography but u can't use ASCII value)
    Comment below for the answer ..

  • @roadtoprogramming8856
    @roadtoprogramming8856 4 ปีที่แล้ว

    Well, right now I am studying assembly language and data structures in c++ for a final exam that is tomorrow. I don't even know one bit about these subject and write now I just checked my future courses like compiler construction, operating system etc. I was like "I can't do this let's give up" but after watching this video and checking your resume. I decided, if you an electrical student can learn c++ then why can't I do this.
    Thanks for the motivation bro.

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

    Rachit, you have done 2 mistakes in your code
    1. if ( ans == UNDEFINED), you should not return ans. If ( ans !=UNDEFINED), then you should return the answer.
    2. You have to assign dp[pos] = ans in the end. Otherwise, dp array is of no use.
    Thanks,

    • @RachitJain
      @RachitJain  5 ปีที่แล้ว

      1 is a typo. And 2 is just fine, you are mistaken. Read about reference in cpp.

    • @balachandra9622
      @balachandra9622 5 ปีที่แล้ว

      Yes you are right. Thanks.

  • @selvaplld
    @selvaplld 4 ปีที่แล้ว

    Is this the kind of Interview that happens in Google or Microsoft? I guess no because we don't write code while explaining the algo. It's the work of Pseudocode which is easy to understand either of the sides. Moreover, if my understanding is correct, the question is to find the string which is in the array and put the spaces if those string found in the pi values. In that case, you should have mentioned Boyer-Moore algo to search quickly. Correct me if I am wrong? It will help me to learn further.

  • @sakshamsingh6351
    @sakshamsingh6351 3 ปีที่แล้ว

    Hi, 2 questions:
    1) where are u assigning the values to dp[] during memoization,
    2) Also the statement should be: if ans!=UNDEFINED then return ans

    • @EspirituAmericano
      @EspirituAmericano 2 ปีที่แล้ว

      1) As he is initializing ans as a reference to the dp array element it will get updated during the computation of ans in the function below.

  • @stewartzayat7526
    @stewartzayat7526 2 ปีที่แล้ว

    Regarding the fun intro to the interview, it hasn't been proven whether or not pi has the property that any finite string of digits occurs in the decimal representation as was described by Clement. It is only conjectured that it does.

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

    Basically this video teaches me not to use a lot of basically. Just kidding, please avoid using a lot filler words. Keep it sufficient enough till the point that people don't start realizing it

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

      Hahahaha, you got me there! I know I have a lot to work upon when it comes to fluently conversing. Hopefully, will become better soon.

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

    Careful rachit, be careful about your personal emails and stuff, read 2 email subjects of yours!

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

      sooo??

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

    These type of excercises are so abstract, I want to see someone at work trying to solve a problem that doesn't fit the scope of basic math knowledge. Just because you can remember a math equation and recreate it doesn't show value as a programmer since literally everything you are trying to do has been done 1000s of times and is widely available on the web. Therefor I think the ability to find instead of generate is of more value.
    But hey every programmer wants to re-invent the wheel anyway.

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

      I bet you can't even do it, shut up.

    • @arpita1shrivas
      @arpita1shrivas 4 ปีที่แล้ว

      Offence to coders.

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

      On one of the problems I solved I had used a similar logic to break down a hashtag into valid words and the optimum solution is the one which has the most number of valid words. There was no library or module at that time which could I quickly find so had it to code it up myself. It is not all as abstract as it would seem.

    • @samb9439
      @samb9439 3 ปีที่แล้ว

      @@arunghontale3189 How'd you determine what was a valid word?

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

      @@samb9439 I'd used a dictionary of words (I guess around 2 million of them) to lookup whether a word is valid or not.

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

    Great video ! Can it be converted into iterative solution ?

  • @stayhungrystayfoolish7130
    @stayhungrystayfoolish7130 4 ปีที่แล้ว

    @Rachit Rachit please correct me if my approach is wrong. For me I will start with largest string in given array and find out if it is present in main string if it is then I will delete that substring from main string and increment space count and similarly will repeat this process for next large strings in given array.

  • @iitgupta2010
    @iitgupta2010 5 ปีที่แล้ว

    Seems some code mistakes
    Mistakes
    1. You return ans, but where did you cache?
    2. Vis[N] you mark it as visited, but it is possible that you won't get the solution at 'pos' so you may need to try some other 'x' which apparently reach to 'pos' but you code says, you can't use it again. Hence failed.
    3. you're first if the condition is wrong, where you check ans=UND.
    as per ur explanation, UND is used to initialized dp/vis array. So they always are equal to UND until n unless you overwrite them.
    Since you put that condition first, you function call to return from there itself, which returns UND as output.
    And ofcouse there few other mistakes as well, your first function tells 'int' as return type but you rather returning printing the solution .:P

    • @RachitJain
      @RachitJain  5 ปีที่แล้ว

      1. You are wrong - Read about references in C++
      2. From given state A, we can only reach to states B > A. So here also, the code will work just fine.
      3. Yeah, that's the typo.
      "Your code is a wrong" is a bold statement.
      Happy Coding!

    • @iitgupta2010
      @iitgupta2010 5 ปีที่แล้ว

      @Rachit Jain I apologies for that, I did not mean to disrespect you. I know you personally. [i'm also from IIT Roorkee, ]