Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • \$\begingroup\$ @doubleunary Those three steps would give an answer, but perhaps there might be shorter calculations that combine some steps. \$\endgroup\$ Commented Nov 1 at 16:20
  • 1
    \$\begingroup\$ Welcome to Code Golf and nice first challenge! Please note that for code-golf most answers are likely to use the worst possible time complexity. (Or even worse than the worst, if that saves a byte.) \$\endgroup\$ Commented Nov 1 at 16:44
  • \$\begingroup\$ Was it taken almost verbatim from HackerRank? \$\endgroup\$ Commented Nov 1 at 17:39
  • 1
    \$\begingroup\$ @Arnauld It was on interviewstreet.com in 2012. The web archive has it on HackerRank only in 2021 \$\endgroup\$ Commented Nov 1 at 17:58
  • 1
    \$\begingroup\$ The HackerRank TOS states that all materials are copyrighted. \$\endgroup\$ Commented Nov 1 at 18:33