93 - Palindrome Index | Strings | Hackerrank Solution | Python

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

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

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

    I googled many solutions and never understood until seeing this video. You are god-like.

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

    The way you make it easy is amazing 🔥🔥 keep it up

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

    Hi, have you tried solving this challenge for the Hacker rank one week preparation mock test? It fails on hidden cases 12 and 13 and I have no idea why. On the discussion someone suggest there is an issue with tests? |Thanks for your video's. Very well explained step-by-step which is essential for a full understanding, and explained in a timely fashion, very good indeed.

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

      Day 3 I believe

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

      Glad you liked the video!!! Is the testcase failing now also with the same code as in the video?

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

      @@HackersRealm It is yes, it passes the majority but fails on 12 and 13. This is only for the mock test of the 7 day preparation course on Hacker Rank. It passes all tests on the standard palindrome challenge page. Just wondered if you had encountered it. I read the discussion and people mentioned poor test cases. Was just interested to see if you'd encountered/solved this issue. Many thanks.

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

      @@matthewking8468 Sometimes, there will be issues in hackerrank, I faced similar issues while solving problems

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

      @@matthewking8468 try this
      left=0
      right=len(s)-1
      index=-1
      def palindrome(s):
      if(s==s[::-1]):
      return True
      else: False
      while(left

  • @sebastian-nunez
    @sebastian-nunez ปีที่แล้ว +1

    I decided to break up the problem into 2 functions but it's basically the same thing but more intuitive to read. Also, I used a 2 pointer approach instead of the reversing the string trick (this can result in an "early return" out of the function)
    def is_palindrome(s):
    if not s:
    return False
    low = 0
    high = len(s) - 1
    while low < high:
    if s[low] != s[high]:
    return False
    low += 1
    high -= 1
    return True
    def palindromeIndex(s):
    if not s or is_palindrome(s):
    return -1
    low = 0
    high = len(s) - 1
    while low < high:
    if s[low] != s[high]:
    removed_low = s[:low] + s[low+1:]
    if is_palindrome(removed_low):
    return low
    removed_high = s[:high] + s[high + 1:]
    if is_palindrome(removed_high):
    return high
    low += 1
    high -= 1
    return -1

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

    very good explanation!

  • @jm.sarmiento
    @jm.sarmiento ปีที่แล้ว +1

    You're a Pro bro. Thanks!

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

      Glad you liked it Jose!!! Happy learning!!!

  • @hongbo-wei
    @hongbo-wei ปีที่แล้ว +1

    Well explained! : )

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

    there's an error in your code. try case aabdadacaa. your should add else: return -1 after if elif. But good explanation, correct logic, keep up the good work!

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

    Nice

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

    Hi, could you please upload the approach for the solution to the flipped matrix on hacker rank?

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

      I will try, which section it belongs to?

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

      @@HackersRealm Interview Preparation -> Week 1

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

    Thank you so much sir

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

      Glad it was helpful!!!

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

    def palindromeIndex(s):
    if s[::-1] == s:
    return -1
    for i in range(len(s)):
    origin = s[:i] + s[i + 1:]
    revers = origin[::-1]
    if origin == revers:
    return i
    else:
    return -1
    This work fine but hackerrank test do not accept this
    for example test: "fvyqxqxynewuebtcuqdwyetyqqisappmunmnldmkttkmdlnmnumppasiqyteywdquctbeuwenyxqxqyvf"
    there are two possibilities remove index 24 "q" or index 25 "q"
    this code remove index 24 but hackerrank test check only for index 25 and it's wrong test should check for both possibilities

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

    The code fails this test case :
    s = "ghdjieta"