DSA- L1- Check if a key is present in every segment of size k in an array

using System;public class GFG{
static public void Main (){
//Code

int[] arr = {5, 8, 7, 12, 14, 3, 9};
int findItem = 8;
int chunk = 2;

int counter = 0;
bool found = false;
for(int i=0; i<arr.Length;i++){
if(arr[i] == findItem ){
found = true;
}
counter++;
if(counter == chunk && found == false )
{
break;
}else{
counter = 0;
found = true;
}
}
Console.WriteLine(found);

}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store