#278·interview

shouldDeleteCurrentNode should also check if the current node is not having other word isEndOfWord as true.

Author: AamirBCreated Jul 10, 2020Updated Jul 10, 2020

https://github.com/mission-peace/interview/blob/94be5deb0c0df30ade2a569cf3056b7cc1e012f4/src/com/interview/suffixprefix/Trie.java#L143

if(shouldDeleteCurrentNode){

        current.children.remove(word.charAt(index));
        //return true if no mappings are left in the map.
        return current.children.size() == 0 && !current.isEndOfWord;

    }

Steps: Add "Aamir" Add "Aami" delete "Aamir" As per the current code this will also delete "Aami"