Minimum characters to be added at front to make string palindrome || GeeksforGeeks || POTD

Поділитися
Вставка
  • Опубліковано 2 січ 2025

КОМЕНТАРІ • 64

  • @mayankrastogi7035
    @mayankrastogi7035 2 роки тому +13

    This logic giving TLE in c++

    • @QuantYogi
      @QuantYogi 2 роки тому +3

      that's because approach seems to be O(n2)

    • @anshulyadav3225
      @anshulyadav3225 Рік тому +5

      ​@@QuantYogi yes this is O(n^2) approach. She has just twisted it.

  • @ayushbhandarkar8394
    @ayushbhandarkar8394 Рік тому +13

    The above approach is a O(n^2) solution,
    There is a better solution in O(nlogn) using binary search and with space complexity O(1)
    and then there is even better solution using dp with tc = O(n) and space O(n)

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

      how is it o(n2)

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

      @@Practice_dsa_together She is resetting the value of i to 0 if the chars are different. So in the worst case, it will restart for every char.

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

      she is updating j with the trim value continuously in case of characters mismatch@@Practice_dsa_together

    • @ManmohanSingh-ng3je
      @ManmohanSingh-ng3je 2 місяці тому

      As it's checking for for (n-1+n-2+n-3---------1) we are only opting out the last character basicaly just checking sequence from 0th index .

    • @ManmohanSingh-ng3je
      @ManmohanSingh-ng3je 2 місяці тому

      yeah Actualy i don't know why its submitting as the testcases constraint is 10^6 which will result in 10^12 operations>4*10^8.

  • @parzival_rex_1509
    @parzival_rex_1509 2 роки тому +13

    @Study with Saumya , try submitting it.
    Your code will give TLE.

  • @vivekkumar-p6r2k
    @vivekkumar-p6r2k Рік тому +5

    TC is O(n^2). if we use KMP algo then TC will O(n).

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

      how is it o(n2)

    • @vivekkumar-p6r2k
      @vivekkumar-p6r2k Рік тому

      ​@@Practice_dsa_together first it will check for n length palindrome, if it is not pal. then it will check for n-1 length pal. like wise (n-2) , (n-3) ...... 3, 2 so the time complexity will be O(n^2) in best case it will be O(n) .

  • @rahilsanghavi9347
    @rahilsanghavi9347 2 роки тому +6

    Why does the same code in C++ give TLE?

  • @raviprakashyadav3741
    @raviprakashyadav3741 Рік тому +3

    In Video you said- answer will be length of (N - longest palindromic substring).
    for test case s = 'BAAA' it will fail
    as per your explanation ans should be 1 but actual answer is 3 for above case??
    pls correct me if I am wrong or mis interpreted your logic

  • @hackcrack4689
    @hackcrack4689 2 роки тому +3

    I'm new in dsa and i got your explaination very easily can you please make a video on how to learn dsa like any roadmap...

  • @awesome_latest_virals6098
    @awesome_latest_virals6098 Рік тому +2

    TLE.......please upload the optimised approach

  • @prateekramani6491
    @prateekramani6491 2 роки тому +1

    How easily u solved this question is Amazing !!

  • @ashwinnair1035
    @ashwinnair1035 Рік тому +1

    TLE mam please tell us how to optimize this code

  • @harshalsonwane5312
    @harshalsonwane5312 2 роки тому +1

    Hii somya ...nice tutorial.... my all douts is cleared..... thank you

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

    How can you surely say that answer will be n-(length of LPS)
    let's say input is xxaxxa
    so acc to you answer will be 6-(lenbgth of "xxaxx")=1 but the expected answer is 2.

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

    whats time complexity of your code ?

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

    Don't you think your code time complexity is O(n^2) in the worst case..

  • @rishabhsinha7250
    @rishabhsinha7250 7 місяців тому

    This can be solved using LPS array in O(n) time

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

    Carryon mam like this... It will help us a lot.. And thnq so much mam

  • @mohdrehan5332
    @mohdrehan5332 8 місяців тому

    Time complexity is O(n^2). It will give TLE. :(

  • @kushagrasinghsisodia9380
    @kushagrasinghsisodia9380 Рік тому +1

    TLE this solution is not optimised

  • @nitroxadi9752
    @nitroxadi9752 Місяць тому

    the above code won't pass all the test cases

  • @AnkushMishra-q5l
    @AnkushMishra-q5l 10 місяців тому

    Aap bhee striver ke student ho ?:I hope u all are doing extremely well !!

  • @devraj-2310
    @devraj-2310 2 роки тому

    ThankYou ma'am

  • @arjavrastogi9259
    @arjavrastogi9259 Рік тому +1

    it will give tle

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

    thanks :)

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

    can any one provide the test case that fail bcz of TLE

  • @easkardi9343
    @easkardi9343 Рік тому +1

    you will get TLE with this solution will have to use DP to optimize it further

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

    I love you what a easy solution 🤩🤩🤩🤩🤩🤩🤩🥰🥰 thanks you

  • @ShivamSingh-ne3en
    @ShivamSingh-ne3en 2 роки тому

    i watched 4 to 5 videos on this problem but i was not satisfied with the solutions there or they seemed difficult but now i am satisfied..best explanation👍

    • @TechWithSaumya
      @TechWithSaumya  2 роки тому +2

      Glad it helped

    • @ShivamSingh-ne3en
      @ShivamSingh-ne3en 2 роки тому +1

      Is it always follow O(n) time complexity??

    • @KittyMaheshwari
      @KittyMaheshwari 2 роки тому +5

      ​@@ShivamSingh-ne3en No bro. How is it even following O(N) complexity.
      It is giving TLE on Interview bit. It is easy but not efficient;

    • @ChiruBillion
      @ChiruBillion 10 місяців тому

      bro its give TLE :(

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

    ig TC - O(n^2). Not an optimized solution

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

    This logic is wrong,please make the logic which can apply on all the test cases ,you might forget some
    test cases,but still appreciate your work madam ji,and you have hide your submission while making video.

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

    Thank you mam . It is a great explanation . Keep helping us and your chanel grow quickly ❣❣❣

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

    😅😅

  • @SagarKumar-rn4cq
    @SagarKumar-rn4cq 2 роки тому

    Mam please use open Board 🙏 and explain logic not code please mam

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

    TLE

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

    it is giving tle

  • @Tushar-fh6qz
    @Tushar-fh6qz Рік тому

    ye O(n^2) approach hai.... janta ko bevkoof mat banao galat solution dalke

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

    Don't you think your code time complexity is O(n^2) in the worst case..