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.
@@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.
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
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!
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
I googled many solutions and never understood until seeing this video. You are god-like.
Glad it was helpful!!!
The way you make it easy is amazing 🔥🔥 keep it up
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.
Day 3 I believe
Glad you liked the video!!! Is the testcase failing now also with the same code as in the video?
@@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.
@@matthewking8468 Sometimes, there will be issues in hackerrank, I faced similar issues while solving problems
@@matthewking8468 try this
left=0
right=len(s)-1
index=-1
def palindrome(s):
if(s==s[::-1]):
return True
else: False
while(left
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
very good explanation!
Glad you liked it!!!
You're a Pro bro. Thanks!
Glad you liked it Jose!!! Happy learning!!!
Well explained! : )
Glad you liked it!!!
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!
Nice
Hi, could you please upload the approach for the solution to the flipped matrix on hacker rank?
I will try, which section it belongs to?
@@HackersRealm Interview Preparation -> Week 1
Thank you so much sir
Glad it was helpful!!!
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
The code fails this test case :
s = "ghdjieta"