Hacker Rank Solutions: Sherlock and the Beast

Hacker Rank Solutions: Sherlock and The Beast

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def largest_decent_number(n)
  return -1 if n == 1 || n == 2

  j = 0
  loop do
    break if n - j <= 2

    if (n - j) % 3 == 0
      return "#{'5' * (n - j) }#{'3' *  j }"
    end
    j += 5
  end

  if (n % 5 == 0)
    '3' * n
  else
    -1
  end
end

test_cases = $stdin.gets.to_i

test_cases.times do
  value = $stdin.gets.to_i

  $stdout.puts largest_decent_number(value)
end

Comments