Also explain with the help of code.Please dont refer gfg code.Its optizised form is implemented in a complex way
Hello,please explain this with the help of code.Unable to implement it through a code
@KetanPandey,
Have you understood the hint video? Else is just implementation, if you don’t want optimised code.
Just for each string(i), find if any of it’s prefix exists as a suffix in any other string(j), and the the left part of word[i]+word[j] is itself a palindrome(simple linear check). If both conditions are true, increment the answer.
Can you provide me the code where it is implemented with the help of hashmap not trie
It would be helpful if you provide me some hints to write this code
@KetanPandey,
Yeah sure, you have understood the solution right. Now implementation is bit tricky, but actually straightforward. See you understood that we have to find prefixes of each string among other strings, right, and then simply linearly check whether the left over part is palindrome. So, one idea is, put all strings in a set, for each string, exclude it from set(so that you don’t match it with itself) and then for each prefix of this string, find whether it exists in set, if yes, check whether the left-over part of the string you picked is palindrome, if both conditions are true, increment the answer and insert this string back into set(because it can be paired with other strings as well).
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.