HackerRank - Two Characters | Full solution and examples | Study Algorithms

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 27

  • @vinoltauro9160
    @vinoltauro9160 4 роки тому +8

    Perfect Solution and great content man ! It'd be helpful if you explain intuitions behind such not so mainstream approaches. Overall this was more than I could ask for. Thanks.

    • @nikoo28
      @nikoo28  4 роки тому +2

      Thank you so much for your support. At around 8:12 in the video, I describe my approach for the problem. Please do watch my video on dynamic programming to get a general idea on how to go about solving these problems.
      ua-cam.com/video/fqvwVE0Ds94/v-deo.html
      Once again, thanks for your support. Please share the video with people you know it may be helpful :)

  • @mr.l3260
    @mr.l3260 2 роки тому

    @Study Algorithms The time complexity of brute force solution mentioned here is not O(n^3)
    No. of possible combinations in the worst case are 26c2 --> A linear scan to check each combination gives you O(26*25/2 * n) which is O(n)
    In the dp solution again, we are constructing the DP matrix with 26*26 elements in the worst case scenario, and linear scan gives O(n) for each remaining combination which is left out after parsing the string. To get the complexity of DP soln, you have used same logic that remaining cases are at best 26C2 ( constant in the worst case), and linear scan is O(n).

  • @CanvasAndCompass
    @CanvasAndCompass 4 роки тому +8

    i dont't know how to implement dynamic programing (Algorithams) in a code ... can you make separate videos for that ... it will be really helpful !

    • @nikoo28
      @nikoo28  4 роки тому +3

      Hi, I have uploaded 2 videos to simplify dynamic programming for you
      Part 1: ua-cam.com/video/tHqTq-H5utI/v-deo.html
      Part 2: ua-cam.com/video/fqvwVE0Ds94/v-deo.html
      Please share them with your friends as well, if you find them helpful.

    • @CanvasAndCompass
      @CanvasAndCompass 4 роки тому +2

      @@nikoo28 yaa ofcourse... i will share ..ur material are really helpful

  • @benhardsim8629
    @benhardsim8629 3 роки тому +3

    i can't see the connection between the problem and the table

  • @aakrandan
    @aakrandan 3 роки тому

    Most underrated channel🙏

  • @vikassanwal1818
    @vikassanwal1818 4 роки тому

    For this problem brute force works fine and all test cases pass without TLE. But I will try to implement it using DP. Thanks :)

    • @nikoo28
      @nikoo28  4 роки тому +1

      Yep, a brute force would work but that is just because the problem is categorised as Easy in HackerRank. With tighter time limits you would need DP.
      Goodluck :)

    • @vikassanwal1818
      @vikassanwal1818 4 роки тому

      @@nikoo28 OK, I got it.

  • @rashidixit1168
    @rashidixit1168 4 роки тому +1

    Nice explanation

  • @SolamanRaji
    @SolamanRaji 3 роки тому

    Awesome explanation :)

  • @mrcool..3168
    @mrcool..3168 2 роки тому +1

    Thank you sir

  • @umairsharif
    @umairsharif 3 роки тому

    Time complexity for the given solution is O(n^2) but not O(n), please correct me if I'm wrong?

    • @nikoo28
      @nikoo28  3 роки тому +1

      If you look at the loops closely, only the outer loop runs till the length(n) of string. The inner loop runs only of NUM_LETTERS = 26 times.
      This will always happen in a constant time, and hence it will not increase exponentially if the length of the string increases.

  • @anuragraj9954
    @anuragraj9954 3 роки тому

    why not 2d char array is taken?? On taking all test cases does not get passed.

    • @nikoo28
      @nikoo28  3 роки тому

      what do you mean by taking a 2d char array. In the solution, I use an integer array where each integer maps to a character. All the test cases pass. Look at the solution in the video description. :)

    • @anuragraj9954
      @anuragraj9954 3 роки тому

      when I took 2d char array my all test cases does not get passed...why??

    • @nikoo28
      @nikoo28  3 роки тому +1

      can't actually help with debugging your code. Try to put in some print statements and run some edge cases. That can help to identify the logical error you are having.

  • @sanskarvidyarthi9895
    @sanskarvidyarthi9895 3 роки тому

    you should add the code along with the theoretical explanation

    • @nikoo28
      @nikoo28  3 роки тому

      Check the video description. You will find a link to the code

  • @Shujaathullakhan
    @Shujaathullakhan 2 роки тому

    i guess dp solution is not constant space coz we are constructing a table

  • @pinkylover911
    @pinkylover911 2 роки тому

    appreciated

  • @annlaosun6260
    @annlaosun6260 4 місяці тому

    DP? And this is marked as easy in HankerRank, lol🤣

  • @gmaingwithsharif1473
    @gmaingwithsharif1473 Рік тому

    bro could we solve it by regex please solve it by regex and give a vidieo tutorial with regex

    • @nikoo28
      @nikoo28  Рік тому

      why do you want to solve it with regex?