Unique Prefix Array

I have tried the implementation of the problem. But the code is giving wrong output. please help me in finding the mistake.
The link of code is as follows:

There are some mistakes in your code:-

  1. Inside the insert() function at line 52, actually at initial stage the root is Null so when your check if the character exists then before increasing the counter you first have to change the node, i.e. swap line 51 and 52 in your code.

  2. There are some mistakes in your find function also, first thing is same here also, you have to first update your temp variable before checking its counter, and another thing is as you are traversing the string in the trie, here you are printing only one character after returning it to main function.
    So here i will suggest you follow something else like insidef find function, keep adding character to the string and check if you find counter == 0 at some point then return the string else keep adding and return at last.
    At last check if the counter is still not 0, then it means no unique prefix present.
    else return the string.

Hope it helps.

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.