Sherlock and The Beast

  • + 0 comments

    My Java solution with o(n) time complexity and o(1) space complexity:

    public static void decentNumber(int n) {
            int fives = n;
            while (fives % 3 != 0) {
                fives -= 5;
            }
            if (fives < 0) {
                System.out.println("-1");
            } else {
                System.out.println("5".repeat(fives) + "3".repeat(n - fives));
            }
        }