Join Regular Classroom : Visit ClassroomTech

Hackwithinfy Solution 2021

BIRTHDAY GIFT

C++

// codewindow.in
// Birthday gift
// code in C++
#include<bits/stdc++.h>
#define  m 10000000007
using namespace std;

int substring_k(string str, int length, int k){
   int count = 0;
   int array[26];
   for (int i = 0; i < length; i++){
      int temp = 0;
      memset(array, 0, sizeof(array));
      for (int j = i; j < length; j++){
         if(array[str[j]- 'a'] == 0){
            temp++;
         }
         array[str[j] - 'a']++;
         if (temp == k){
            count++;
         }
         if(temp > k){
            break;
         }
      }
   }
   return count;
}
int main(){
   string str;
   cin>>str;
   int length = str.length();
   int k;
   cin>>k;
   cout<<substring_k(str, length, k)%m;
   return 0;
}
//end

Follow us

Also Checkout