Average Value of Even Numbers That Are Divisible by Three - Problem
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.
Input & Output
Example 1 — Mixed Numbers
$
Input:
nums = [1,3,6,10,12,15]
›
Output:
9
💡 Note:
Numbers divisible by both 2 and 3: 6 (even, 6÷3=2) and 12 (even, 12÷3=4). Average = (6+12)/2 = 9
Example 2 — No Valid Numbers
$
Input:
nums = [1,2,4,7,10]
›
Output:
0
💡 Note:
No numbers are both even AND divisible by 3. 2,4,10 are even but not divisible by 3. Return 0.
Example 3 — Single Valid Number
$
Input:
nums = [4,4,9,6]
›
Output:
6
💡 Note:
Only 6 is both even and divisible by 3. Average = 6/1 = 6
Constraints
- 1 ≤ nums.length ≤ 1000
- 1 ≤ nums[i] ≤ 1000
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array of positive integers
2
Filter
Find numbers that are both even AND divisible by 3
3
Average
Calculate sum/count, rounded down
Key Takeaway
🎯 Key Insight: Numbers divisible by both 2 and 3 are exactly those divisible by 6
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code