[Solved] count distinct elements in every window of size k


You have the equal elements in array, when m=8 and l=6=>i=l:
in first loop, i=6, condition is i<m, then the execution of next for loop starts and in the second for loop, till j=5<6 condition, there are no equal elements so codes continue with

      if(i==j){ //i =6, j =6
          count++;
      }

in the next execution of code, count will be 1. After if(i==j) condition, 2nd loop is over and then get back to first loop with the condition i=7<8 (because of the increment i++).
in case of i=7 and i=7<8, code starts the execution of next for loop again, and in the second for loop, till j=6<7 condition, there are equal elements inside array: arr[7] and arr[1] are equal 68 so you will go to the following if statement and then loop will break and prints count as 1:

      if (arr[7] == arr[1]) {
         break;
      }

Debug your codes on the IDE. You will see the result.

2

solved count distinct elements in every window of size k