educative.io

I think the big space complexity here might be wrong

When it describes the space complexity of the algorithm, it says “The space complexity of the algorithm is O(K), as we will be storing a maximum of ‘K+1’ characters in the HashMap.” But in this case, there is no K, there are always 2 buckets of fruit. (I think it should be constant space O(1)). I think something might have been copied and pasted from the previous stage, Longest Substring with K Distinct Characters, which does have a K.

1 Like

Thanks @Brendan_Whiting for pointing this out. Yes, the algorithm run in constant space as we will be storing a maximum of three types of fruits in the frequency map. We will fix the text. Thanks!