Current Codility challenge is called Gallium 2018 and again I managed to make a solution that is awarded with a **Golden Award**. This one was a very interesting brain puzzle for me and it took me a white to figure it out.

The challenge ends tomorrow so if you like to try it by yourself these are the requirements.

Write a function:

`class Solution { public int solution(int[] A); }`

that, given an array of N positive integers, returns the maximum number of trailing zeros of the number obtained by multiplying three **different** elements from the array. Numbers are considered different if they are at different positions in the array.

For example, given A = [7, 15, 6, 20, 5, 10], the function should return 3 (you can obtain three trailing zeros by taking the product of numbers 15, 20 and 10 or 20, 5 and 10).

For another example, given A = [25, 10, 25, 10, 32], the function should return 4 (you can obtain four trailing zeros by taking the product of numbers 25, 25 and 32).

Assume that:

- N is an integer within the range [3..100,000];
- each element of array A is an integer within the range [1..1,000,000,000].

Complexity:

- expected worst-case time complexity is O(N*log(max(A)));
- expected worst-case space complexity is O(N) (not counting the storage required for input arguments).

Here is the award certificate that I’ve received.

Good luck and happy coding,

J.

### Like this:

Like Loading...