Online C++ Compiler

#include <bits/stdc++.h> using namespace std; int sub_k_ones(string str, int length, int k) { int count = 0; int total_1 = 0; int arr_fre[length + 1] = {0}; arr_fre[0] = 1; for (int i = 0; i < length; i++) { total_1 = total_1 + (str[i] - '0'); if (total_1 >= k) { count = count + arr_fre[total_1 - k]; } arr_fre[total_1]++; } return count; } int main() { string str = "10000100000"; int length = str.length(); int k = 2; cout<<"Count of substrings of a binary string containing K ones are: "<<sub_k_ones(str, length, k) << endl; return 0; }