We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Why mix output logic with determination of x and y?
Why use loops to build string (or Stringbuilder)? Obfuscates code.
Here is my solution:-
static void decentNumber(int n)
{
int x = 0;
int y = 0;
for (int i = n; i >= 0; i--)
{
if (i % 3 == 0 && (n - i) % 5 == 0)
{
x = i;
y = n - i;
break;
}
}
var res = y == 0 && x==0? "-1" : new string('5', x) + new string('3', y);
Console.WriteLine(res);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
Why mix output logic with determination of x and y?
Why use loops to build string (or Stringbuilder)? Obfuscates code.
Here is my solution:-