Friend Groups in A Line : What am I doing wrong ? Problem Code : FRIENDGR

Please someone tell why am I getting WA for following code ?
Edge test cases with answers are appreciated.

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main() {

ios_base::sync_with_stdio(false);

cin.tie(NULL);

int t;

cin>>t;

while(t--)

{

   int n,k;

   cin>>n>>k;

   string str;

   cin>>str;

   if(k==0)

   {

       int sums = 0;

       for(char c : str) if(c=='1') sums++;

       cout<<sums<<"\n";

       continue;

   }

   int groups1 = 0;

   int groups2 = 0;

   int i = 0;

   int temp;

   while(i<n)

   {

       temp = i;

       if(str[i]=='1')

       {

           if(groups1==0) groups1++;

           if(i==n-1) break;

           int j=i+1;

           while(j<i+k+1)

           {

               if(str[j]=='1') i=j;

               j++;

           }

           if(temp==i && j>=n) break;

           if(temp==i && j<n)

           {

               if(str[j]=='1')

               {

                   swap(str[j],str[j-1]);

                   //cout<<"Swapping done\n";

                   i=j-1;

               }

               else 

               {

                   //cout<<i<<" "<<j<<"\n";

                   i=j+1;

                   groups1++;

               }

           }

       }

       else i++;

   }

   

   i = n-1;

   while(i>=0)

   {

       temp = i;

       if(str[i]=='1')

       {

           if(groups2==0) groups2++;

           if(i==0) break;

           int j=i-1;

           while(j>i-k-1)

           {

               if(str[j]=='1') i=j;

               j--;

           }

           if(temp==i && j<0) break;

           if(temp==i && j>=0)

           {

               if(str[j]=='1')

               {

                   swap(str[j],str[j+1]);

                   //cout<<"Swapping done\n";

                   i=j+1;

               }

               else 

               {

                   //cout<<i<<" "<<j<<"\n";

                   i=j-1;

                   groups2++;

               }

           }

       }

       else i--;

   }

   cout<<min(groups1,groups2)<<"\n";

}

return 0;

//11010001001101

//111001001010101 -> 111001001010101

}

Multiple friends can be at the same position, so for k==0, ans will not be the total number of people in the queue

I appreciate your reply but can you please provide any test case for that ?
Cause I am not able to understand.
Thank you!

For this case N=4 and K=0 and S=0110
The answer should be 1
both the 1st and 2nd friend can stand at the index 2.

Got that, Thanks!

Anyone who was trying to solve the problem without reading the last line.

It is possible that there is more than one person standing in the same position after the movements.

I missed that line and wasted 1 hr.