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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.