A produce warehouse ships crates of mixed weight, and only crates that are both even in weight and a multiple of three qualify for the premium-blend shelf — a crate weighing, say, 5 or 9 units does not qualify, but one weighing 6 or -12 does. Given the recorded weight of every crate in a shipment, compute the average weight of the qualifying crates, using integer division that truncates toward zero. If no crate in the shipment qualifies, report 0 instead.
n, the number of crates in the shipment.n space-separated integers, the weight of each crate in order.A single integer: the truncated-toward-zero average weight of every crate whose weight is both even and divisible by three, or 0 if no crate qualifies.
1 <= n <= 1000-1000 <= weight_i <= 1000Example 1
Input
5 1 3 6 10 12
Expected
9
Explanation
Weights 6 and 12 are both even and divisible by three, so they qualify (10 is even but not divisible by three, and 1 and 3 are odd or not both, so they are excluded). Their average is (6+12)/2 = 9.
Example 2
Input
3 1 5 7
Expected
0
Explanation
None of the weights 1, 5, 7 are even, so no crate qualifies for the premium-blend shelf, and the output is 0 by convention.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →