educative.io

Question about the given code

if (str == null || str.length() == 0 || str.length() < k)
throw new IllegalArgumentException();

Why not just return str.length() if str.length() < k if the question is looking for the length of the longest substring in it with no more than K distinct characters ?

Hi,

That’s a valid concern. Thank you very much for pointing that out. We have made the required changes.