HackerRank Weighted Uniform Strings Solution


 Problem link :https://www.hackerrank.com/challenges/weighted-uniform-string/problem

Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long  t,n,i,a[100]= {0},c=1,v,l;
    string s;
    cin>>s;
    l=s.size();
    cin>>n;
    for(i=0; i<l; i++)
    {
        if(s[i]==s[i+1])
        {
            c++;
            if(a[s[i]-96]<c)
                a[s[i]-96]=c;
        }
        else
        {
            if(a[s[i]-96]<c)
                a[s[i]-96]=c;
            c=1;
        }
    }
    for(int j=0; j<n; j++)
    {
        cin>>v;
        int ans=0;
        for(i=1; i<27; i++)
        {
            if(v%i==0)
            {
                if(v/i<=a[i])
                {
                    ans=1;
                    break;
                }
                else
                    ans=0;
            }
        }
        if(ans==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}


No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.