JuniorArrayMath

Average Value of Even Numbers That Are Divisible by Three

Given an integer array nums of positive integers, return the average value of all even integers that are divisible by 3.

Note that the average of n elements is the sum of the n elements divided by n and rounded down to the nearest integer.

If there is no integer in nums that satisfies the requirement, return 0.

Example 1
Inputnums = [1,3,6,10,12,15]
Output9
6 and 12 are even numbers that are divisible by 3, and (6 + 12) / 2 = 9.
Example 2
Inputnums = [1,2,4,7,10]
Output0
There is no single number that satisfies the requirement, so return 0.

Constraints

  • 1 <= nums.length <= 1000
  • 1 <= nums[i] <= 1000

Asked at 1 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate