Good Reductions
Practice
4.7 (3 votes)
Data structures
Math
Basics of implementation
Basic programming
Basic math
Problem
82% Success 229 Attempts 20 Points 1.5s Time Limit 256MB Memory 1024 KB Max Code

You are given a large number \(S\) containing \(N\) digits.If sum of digits in the number is odd than the number is considered good.You can do the following operation any number of times to make the given number good:
Operation -
Divide the number by \(10\).

Task :

Return the length of maximum possible good number from the given number, if a good number is not achievable then return \(-1\).

Assumption :

\(S=1221\)

Approach :

The sum of digits in \(S\) is \(6\) if we divide \(S\) by \(10\) , \(1 \) will be removed and sum of digits will become \(5\) and length of \(S\) becomes \(3\) so the answer is \(3\)

Function description:

Complete the function solve provided in the editor. This function takes the following two parameters and returns the required answer:

\(N\) represents the number of digits in the given number.

\(S\) represents the given number.

Input format :

Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).

The first line contains \(T\) denoting the number of test cases. also specifies the number of times you have to run the solve function on a different set of inputs.

For each test case, the first line contains the integer \(N\) and second line contains the number \(S\).

Output format :

For each test case, print the length of good number obtained by using minimum number of operations.

Constraints:

\(1 \leq T \leq 10^{}\)

\(1 \leq N \leq 10^{5}\)  

 

Code snippets (also called starter code/boilerplate code)

This question has code snippets for C, CPP, Java, and Python.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
96 votes
Tags:
ReadyMathematicsApprovedEasyMathamatics
Points:20
11 votes
Tags:
Basic ProgrammingOpenApprovedEasyMathamatics
Points:20
4 votes
Tags:
Easy