HackerEarth's basic programming solutions( IT’S MAGIC!, Two Strings, Print the Numbers ) :

Problem 15: IT’S MAGIC!

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,min=10000000000,i,sum=0,index=-1,j;
cin>>n;
long long a[n];
for(i=0;i<n;i++)
{
    cin>>a[i];
    sum+=a[i]; // sum now stores the sum of array
}
for(j=0;j<n;j++)
{
    if((sum-a[j])%7==0 && a[j]<min)
    {
        min=a[j];
        index=j;
    }
}
cout<<index;
}

In this problem , simply we have to remove the smallest multiple of 7 from the array. Read the above code and try it with the example given below to understand.

input                             output

5
14 7 8 2 4          1


 

 

 

Problem 16: Two Strings

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        string s1,s2;
        cin>>s1>>s2;
        sort(s1.begin(),s1.end()); //sorting string s1
sort(s2.begin(),s2.end()); //sorting string s2
        if(s1==s2)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }
    }
}

This code is simple. There's no need for any explanation.
 

 

 

 

Problem 17: Print the Numbers

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int e;
        cin>>e;
        cout<<e<<" ";
    }
}

This code is simple. There's no need for any explanation.
 

 

 

Guys , if you have any queries related to a question or need more explanation, comment down below! 

 

Comments

Popular posts from this blog

Coursera's Algorithmic toolbox assignment solutions( Sum of Two Digits, Maximum Pairwise Product ) :

HackerEarth's basic programming solutions( Seating Arrangement, Zoos, Anagrams ) :

HackerEarth's basic programming solutions( Minimize Cost, Magical Word, Best Index ) :