Multiples of 2 and 3

Ninja is bored with his previous game of numbers, so now he is playing with divisors.

He is given 'N' numbers, and his task is to return the sum of all numbers which is divisible by 2 or 3.

Let the number given to him be - 1, 2, 3, 5, 6. As 2, 3, and 6 is divisible by either 2 or 3 we return 2 + 3 + 6 = 11.

Input Format:
The first line contains ‘T’, denoting the number of test cases.

Each test case contains a single integer ‘N’, denoting the number of elements given to Ninja.

The next line contains the ‘N’ elements given to Ninja.
Output Format:
For each test case, return an integer denoting the sum of numbers divisible by 2 or 3.
Note:
You are not required to print the expected output. It has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 10
1 <= N <= 10^3
0 <= input[i] <= 10^3

Where ‘T’ denotes the number of test cases and ‘N’ is the elements given to Ninja and input[i] denotes theith input.

Time Limit: 1 sec  
CodingNinjas
author
2y

I followed brute force approach to solve this question.

Step 1 : Iterate the array

Step 2 : Check the condition if each iteration integer is completely divisible by 2 or 3 or not. If divisible add to su...read more

CodingNinjas
author
2y
Brute force

The key here is to traverse all the elements in the given array and check whether it is divisible by 2 or 3, and simultaneously add the value to the sum.

The steps are as follows:

  • We will ini...read more
Help your peers!
Add answer anonymously...
Bank of America Software Developer 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