Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
senthil kumar
In correct logic in Deletion Operation

senthil kumar

Apr 3, 2024

As we are using array datatype for children, its length is always constraint as the size is defined during initialization.

So the below code to check the presence of children for a node will always return 26 irrespective whether there is actual value or null)

return current.children.length == 0; // Return true if no children exist

We Should use below code instead

for (int i = 0; i < 26; i++) { if (node.children[i] != null) { return true; } } return false;

1

0

Comments
Comments
Sachin Dev S
Sachin Dev S10 months ago

correct, I was also wondering the same

On this page