Editorial for THICC '17 P5 - Smarties


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Kirito

For 40% of points, one can iterate through all subarrays, and count how many of them have at least K distinct elements.

Time Complexity: O(N3) or O(N3logN)

For the remaining 60% of points, we can employ a two pointer approach. Let there be two pointers, l and r such that F[1r],F[2r],,F[lr] have K elements. This can be achieved using a counter array. Implementation is left to the reader as an exercise.

Time Complexity: O(N)


Comments

There are no comments at the moment.