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.
While not the optimal, I was happy with this one in Java:
publicstaticvoiddecentNumber(intn){// Decent number s of length n, can be represented as// x = Number of sets of 5// y = Number of Sets of 3// (3*x) + (5*y) = n;// Isolating x// x = (n - (5*y)) / 3// Need to solve for lowest integer y > 0 than gives integer x > 0for(inty=0;y<n;y++){if((n-(5*y))%3==0){intx=(n-(5*y))/3;if(x<0){break;}StringdecentForLength="5".repeat(x*3)+"3".repeat(y*5);System.out.println(decentForLength);return;}}System.out.println(-1);}
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 →
While not the optimal, I was happy with this one in Java: