Hackerrank – Sherlock and The Beast

Problem Statement
A description of the problem can be found on Hackerrank.

Solution
Create two number: one of them represents fives_count and the second <.code>threes_count. Initialize fives_count as length of the number and threes_count as 0. Check if fives_count is divisible by 3 and threes_count is divisible by 5. Then substract 5 from fives_count and add 5 to threes_countContinue until condition holds and print this number. If it is not possible return -1.

We want to get the biggest number from all permutations. If we start the iteration with maximum count of fives, we are sure that if the condition holds, we get the biggest number.

I created solution in:

All solutions are also available on my GitHub.

Scala

Java

JavaScript

Ruby