PROBLEM LINK:
Contest: Hey Newbees, Here is Some Honey (Round-3)
Idea inspired from-CF-1291A
Author: Samia Rahman
Tester: Arefin Labib,Sanjida Akter,Redowan Ibrahim
Editorialist: Samia Rahman
Please read this blog if you are a Python user and I apologize to you
DIFFICULTY:
SIMPLE.
PREREQUISITES:
Greedy
PROBLEM:
You will be given an integer number.You have to find out the number of minimum number of moves means minimum digits you need to remove from the integer to make it a ONO (You can shuffle the digits as many times as you want which will not count as a move)
ONO means Odd Not Odd more specifically it’s a number which is odd but the summation of it’s digits are even.
EXPLANATION:
We just need to calculate how many odd digits we have in a number.
If there is no odd digit means the number is even.Ans is -1.
If there are even numbers of odd digits in a number(E.g-33, 3322, 3333222),sum of the number’s digits is already even and the number is either odd(e.g-33) or through free shuffling we can make it odd{E.g-2233,2323,3223 etc for the number (3322)} .So we don’t need any move.and is 0.
If there are odd numbers of odd (E.g-333 , 33322) we need to remove a digit to make the sum odd.ans is 1.
Corner case-If there is only one odd (E.g- 3 , 3222 ) we can’t remove any digit to make it a ONO.Because if we remove the odd digit the number will be an even.If we remove even digits sum will still be odd.So if there is only one odd ans is -1.
TIME COMPLEXITY:
O(N)
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
int main()
{
ll t,j;
cin>>t;
for(j=0;j<t;j++)
{
ll odd=0,i;
string s;
cin>>s;
for(i=0;i<s.size();i++)
{
if((s[i]-'0')%2==1)
odd++;
}
if(odd%2==0)
{
if(odd==0)
cout<<"-1"<<endl;
else
cout<<"0"<<endl;
}
else
{
if(odd==1)
cout<<"-1"<<endl;
else
cout<<"1"<<endl;
}
}
return 0;
}
One of the Participants named akamoha’s solve in Python
Click here