Technically the correct time complexity is Θ(n). Reading the input string requires Θ(n) and reading the dictionary requires O(n). Θ(n) + O(n) = Θ(n) I'm not opinionated, but if you state that this algorithm runs in O(n) it means that the worst case is linear; this implies the existence of some cases where the algorithm runs better, but it is not true because the reading of the input string defines the algorithm's lower bound in terms of time complexity. In any case great video and I wish you the best of luck with your new project :)
Zack Do yes, but one of them is simply more precise :) In this case it's easy to calculate Big Theta and gives more information about the time complexity. I know that Big O is more mainstream than Big Theta...
because they will give you strings that could be palindrome, but not currently a palindrome. This solution will work only if the string they give you is currently a palindrome.
Can you provide a simplified Java code version of this exercise? I have managed to do it using HashMap but have a lot of code while yours seems so simple. Thanks.
The question asks if a string can be rearranged to BE a palindrome. It doesn’t just check if it’s a palindrome. So for example, “dda” should return true because it can be rearranged to “dad”
Technically the correct time complexity is Θ(n).
Reading the input string requires Θ(n) and reading the dictionary requires O(n).
Θ(n) + O(n) = Θ(n)
I'm not opinionated, but if you state that this algorithm runs in O(n) it means that the worst case is linear; this implies the existence of some cases where the algorithm runs better, but it is not true because the reading of the input string defines the algorithm's lower bound in terms of time complexity.
In any case great video and I wish you the best of luck with your new project :)
It's both, everything that is Θ(n) is also O(n) but not vice versa.
Zack Do yes, but one of them is simply more precise :)
In this case it's easy to calculate Big Theta and gives more information about the time complexity.
I know that Big O is more mainstream than Big Theta...
it' not gonna be O(n) if you use set() because it removes all duplicates and iteration can be performed in n/2 + 1 passes for the worst case.
6:45
Joma: imagine if I had another odd number....
Me: (think K...)
Joma: for example like K....
Me: what!?
easy python solution using itertools:
import itertools as it
def find_palindrome(st):
st = st.lower()
x = list(it.permutations(st, len(st)))
for i in x:
s1 = "".join(i)
flag = False
if s1 == s1[::-1] :
return s1
return False
print(find_palindrome( input() ))
Sir I love your videos I'm from Pakistan.exited for your next video on your main channel
Please keep posting this is some amazing content right here
Question : why can't we just reverse the string and test if the reversed version = string ?
because they will give you strings that could be palindrome, but not currently a palindrome. This solution will work only if the string they give you is currently a palindrome.
qqaao ... we can make pa;indrome , bro are you sick or am i hogh too much ???
This was the first problem I solved with Python 💪
Now joma being a ronin. There is no more naniiiii😒
Why can’t qqaao be made into a palindrome? Like qaoaq?
The example was qqaaao, not qqaao
Joma Class Oooh sorry my screen was too small lmao
great video thanks
what happened to the old logo 😭
Thanks jomaoppa :)
Can you provide a simplified Java code version of this exercise? I have managed to do it using HashMap but have a lot of code while yours seems so simple. Thanks.
great video but the way you say palindrome tho...
Puh-linndrahm
How about this:-
def isPalindrome(s):
If (s==s[::-1]):
return True
return False
🤔🤔
The question asks if a string can be rearranged to BE a palindrome. It doesn’t just check if it’s a palindrome.
So for example, “dda” should return true because it can be rearranged to “dad”
@@JomaClass o...oh, domo🙇. Nice solution
😄