Hello! can someone explain why we need the ‘|| 0’ in the. below line?
if (wordsSeen[word] > (wordFrequency[word] || 0)) {
break;
}
I’ve tried to work through different examples but can’t really justify having it there. Isn’t wordsSeen[word] always greater than zero?
Also for the space complexity -
The space complexity of the algorithm is O(M) since at most, we will be storing all the words in the two HashMaps. In the worst case, we also need O(N) space for the resulting list. So, the overall space complexity of the algorithm will be O(M+N).
so is it O(M+N) or O(M)? I’m confused whether they are the same or different
Thanks in advance!!
Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Solution Review: Problem Challenge 4 - Grokking the Coding Interview: Patterns for Coding Questions
Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Solution Review: Problem Challenge 4 - Grokking the Coding Interview: Patterns for Coding Questions