Talentd
FleetCode

2455. Average Value of Even Numbers That Are Divisible by Three

Easy63.6% acceptance2 companies

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.

Example 1:

Input: nums = [1,3,6,10,12,15]
Output: 9
Explanation: 6 and 12 are even numbers that are divisible by 3. (6 + 12) / 2 = 9.

Example 2:

Input: nums = [1,2,4,7,10]
Output: 0
Explanation: There is no single number that satisfies the requirement, so return 0.

Constraints:

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

Asked at 2 companies

Topics

Hints open one at a time

Hint 1
What is the property of a number if it is divisible by both 2 and 3 at the same time?
Hint 2
It is equivalent to finding all the numbers that are divisible by 6.
1:58
Still stuck?Read 4 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def averageValue(self, nums: List[int]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[1,3,6,10,12,15]
Input
[1,2,4,7,10]
Your code is saved on this device.Solution