Ad
  • Custom User Avatar

    I really like your O(1) solution... unclear how you solved that nominal?

  • Custom User Avatar

    No matter how much you like this solution, it's bad. If you have considerations related to performance, then you shoud be concerned by the fact it contains a loop. This problem does not require a loop to solve it. Solution with loop requires many operations, and is slow. Solutions without loop always perform like a dozen or two of of operations total, no matter how large is n.