Sum of even & odd

Ninja got a test problem in which he was given an integer and he had to find the sum of even digits and odd digits separately.

Ninja is very weak in studies and didn’t know much about odd and even concepts. But he said if he got the solution he can easily understand the concepts of even and odd very clearly on his own.

Ninja asks for your help to find the solution. Can you help Ninja out?

Note:

Digits mean numbers, not the places. That is if the given integer is "13245",  even digits are 2 & 4 and odd digits are 1, 3 & 5.
Input format :
The first line of input contains an integer ‘T’ denoting the number of test cases. Then each test case follows:

The first and only line of each test case contains an integer ‘N’ denoting the input integer.
Output format :
The only line of output contains two single space-separated integers denoting the sum of even digits and sum of odd digits respectively.

Output for each test cases will be printed on a separate line

Note:

You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints
 1 <= T <= 5
 0 <= N <= 10 ^ 18


Time Limit: 1 sec.
CodingNinjas
author
2y
Mathematical Operations

Use modulo operation to find digits of numbers.

Algorithm:

  • First, make an iteration till the given integer ‘num’ is greater than 0.
  • Store the one’s place digit in a variable.
  • Che...read more
Anonymous
1y

We can also follow this approach: first perform mergeSort

Then do run a loop on sorted array and and for every index value find the required value by target - arr[i] ,

Then for evry required value -You...read more

Help your peers!
Add answer anonymously...
Delta Air Lines SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter