Untitled
unknown
plain_text
3 years ago
1.3 kB
11
Indexable
/*
Your submission failed for the following input
A : [ 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1 ]
B : 2
Test As Custom Input
The expected return value:
10 17 18 30 36 37 38
Your function returned the following:
10 17 18 30
*/
#include<iostream>
#include<vector>
using namespace std;
void func(vector<int> &ans, vector<int> &A, int B, int l, int u){
int length = u - l + 1;
if(length >= 2*B+1){
for(int k = l+B; k < (u-B+1); k++){
ans.push_back(k);
}
}
}
vector<int> solve(vector<int> &A, int B) {
int l=0, u=0,f=0;
vector<int> ans;
if(B == 0) {
for(int k=0; k<A.size(); k++){
ans.push_back(k);
}
return ans;
}
for(int i=1; i<A.size(); i++){
if(A[i] != A[i-1]){
if(f==0){
l = i-1; u = i;
f = 1;
}
else{
u = i;
}
}
else{
if(l != u){
cout<<"\n"<<l<<" "<<u<<endl;
func(ans,A,B,l,u);
}
l = u = i;
f = 0;
}
}
return ans;
}Editor is loading...