char[] fruits = { ‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘B’, ‘B’, ‘B’,‘A’,‘D’, ‘B’, ‘D’, ‘D’, ‘D’, ‘D’, ‘D’ };
The solution will not work for above input, output shout be 12 but the output is 10
A-7
D-5
char[] fruits = { ‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘B’, ‘B’, ‘B’,‘A’,‘D’, ‘B’, ‘D’, ‘D’, ‘D’, ‘D’, ‘D’ };
The solution will not work for above input, output shout be 12 but the output is 10
A-7
D-5
10 is the right answer, you cannot skip a tree so when your one basket has A and another has B, when you windowEnd pointer reaches D, you need to stop, as its the 3rd Character and you can’t put it in any basket , also you cannot skip it.