Technical Interview: Check if string is a palindrome

preview_player
Показать описание
Problem: Given two strings, write a function to decide if one is a permutation of the other.

This video is part of the "Technical Interview Problems" series on various problems that arise in a technical interview setting. The solutions in this series focus on the Python language.

The code used in this video may be found here:

Website:
Рекомендации по теме
Комментарии
Автор

It is a interesting question . But many times interviewer want from an applier to write an exactly algorithm which perform a comparison .

In this case we can provide something like :


import string

print("If string is not a palindrome you will be alerted!")

s = "Dammit I'm mad"

s = s.translate(str.maketrans('', '', ", "")
print(s)

for x, y in zip(range(int(len(s) / 2)), range(int(len(s) - 1), int(len(s) / 2), -1)):
if s[x] != s[y]:
print('Not equal!')
break



Because sometimes he wishes to know if you understand intricacies of comparison itself.

deserve_it
Автор

Thank you so much. Can you also give a solution in Python for finding the longest palindromic sub-string in a string?

joyoptimal
Автор

Thanks so much for the explanation! 😊. I just started programming in college, and I was stuck on this problem, but you helped me understand it.

TheCutiepie
Автор

What to do if import string is not to be used.. Means what's the logic?

bju
Автор

Wouldn't it work if you had two sums variables, each returning the sum of ASCII codes of characters of each string ? if the sums are equal then it is a permutation.

surrenderTeo
Автор

Thanks, but I am using trinket, and after trying both the way in the video and the way in your pinned comment, it still gives me an error when I try to code it to remove punctuation.
Any idea how to fix this?

bendyalien
Автор

Hi,
while running the below. code,
str = str.translate(None, string.punctuation)
print(str)

i am getting below error:
str = str.translate(None, string.punctuation)
TypeError: translate() takes exactly one argument (2 given)

bharatapar
Автор

for me it says TypeError: translate() takes exactly one argument (2 given)

jonallen
Автор

you misspell the word madam. It should be written madame

benderbendingrofriguez
join shbcf.ru