We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intn=sc.nextInt();intk=sc.nextInt();inta[]=newint[n];for(inti=0;i<n;i++)a[i]=sc.nextInt();intstart=0;intcount=0;while(start<n){intj=k-1;if((start+j)>=n)j=n-start-1;while((start+j)>=0&&a[start+j]!=1){j--;}if(j>k||j<(-k+1)||(start+j)==(-1)){count=-1;break;}else{start=start+j+k;count++;}}System.out.println(count);/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Goodland Electricity
You are viewing a single comment's thread. Return to all comments →
My Code: