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: \mathcal O(N^3) or \mathcal O(N^3 \log N)

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

Time Complexity: \mathcal O(N)


Comments

There are no comments at the moment.