158A. Next Round - Codeforces Solution C++

  Problem Link : 158A. Next Round 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];
		if(arr[k]==0)
		{
		    while(k>0 && arr[k]==0)
		        k--;
		    cout<<k;      
		    
		}
		else
		{
        	int i=k+1;
        	while(i<=n && arr[i]==arr[k])
        	{
        	    i++;
        	}
        	cout<<i-1;
}
		}
		

	

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!