Question: Amazon, Online Assessment Questions | Minimum Possible Cost of Shipping | Amazon Prime Day | 2023
1
Entering edit mode

ADD COMMENTlink 16 months ago PoGo 2.4k
0
Entering edit mode

#include <bits/stdc++.h>

using namespace std;

 

int main()

{

    string s;

    cin >> s;

    int n = s.length();

    int k;

    cin >> k;

    int r = 1;

    int ans = 0;

    map<char, int> pre, suf;

    for (int i = 0; i < n; i++)

    {

        suf[s[i]]++;

    }

    while (r < n - 1)

    {

        pre[s[r-1]]++;

        if(suf[s[r-1]]==1) suf.erase(s[r-1]);

        else suf[s[r-1]]--;

        int x = 0;

        for(auto it:pre){

            if(suf.find(it.first)!=suf.end()) x++;

           

        }

        if(x>k) ans++;

        r++;

    }

    cout<<ans<<endl;

}

ADD COMMENTlink 16 months ago Shivam • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts