flavors[i] is the flavor of candy i. You must give a friend exactly gift candies that lie next to each other and keep the rest. You want to be left with as many different flavors as possible.
Return the largest number of distinct flavors among the candies you keep.flavors=[1, 3, 3, 2, 1], gift=2 → 3
Give away the two 3s (positions 1 and 2). That leaves 1, 2, 1: two flavors. No other gift leaves more.
flavors=[4, 5, 6, 4], gift=1 → 3
Give away one of the 4s, keeping flavors 4, 5 and 6.
flavors=[7, 8], gift=0 → 2
Nothing has to be given, so both flavors stay.
flavors=[1, 3, 3, 2, 1], gift=2
3
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.