would you please check whether the code is correct for palinrome pair question.
I have done it using tries.
The testcase that i have used are all passing
but would you check for corner conditions?
Palindrome pair using tries
Firstly,i have inserted reverse of all the elements in trie…then i traversed the array while checking for each element: if the each character of string is found then return true(for cases with full strings as palindromes) and for partial cases,i have checked for till where the prefix of the element is prent and for the remaining characters of the string i have checked whether this is palindorme or not,if palindrome then return tur else false
take input as:- 2 abcd dcbx
Your code will give true for second, case.
Your code is not handling the suffix cases, also for the prefix cases you can see the above example types are not passing.
What all changes should i make?
Basically trie is for prefix type of things only and here you have to check for suffix also, so best and fast way to do is to use map as mentioned in the video
I am unable to write all the prefixes in the hashmap…could you please forward the codee?
and if possible would you suggest changes in this trie code too?
As i said trie doesn’t seems to be feasible approach for this.
You dont have to write the prefixes in hashmap approach, just run loop from 0 to n and take each string.
Then for each string you have to iterate from 0 to length, and at every particular index you have to check if its reverse is present and if present then is remaining string palindrome or not.
I suggest you to rewatch the video it is very well explained, its implementation is very simple, try it once more.
Tell me after trying if not able to write the code then i will provide it to you
i have tried many time but unable to implement this hashing approach…could you send the code?
i can send you the code, but first tell me what problem are you facing in implementing this so that you can learn that.
You know how to use map? Are you getting the logic explained in the video?
I have seen the video and have understood that for a particular string i’ll have to check whether its reverse is present and not and for the remaning elements in the string i have to check whether it is palindrome or not…so if i iterate in the array of string,for 1st element how will i check whether its reverse is present in the remainning array or not…if use 2 nested loops it will take n^2 time and the video says we will store all the possible prefixes of a string in hashmap…so how do i thi??? a more promiment ellaboration on its implementation would be helpful