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.

5
  • Obviously not since you cannot take logs of negative values. But since we are just looking at digits, just wrap it in np.abs() and then it works. Commented Oct 12, 2018 at 8:45
  • 14
    More importantly, this does not work for e.g. 1000 and 1; first_n_digits(1000,1) returns 10. This method always has problems with digits followed by lots of zeros. Commented Oct 12, 2018 at 8:58
  • 3
    this turns out to be slower than string conversion/list slicing for large N Commented Dec 3, 2018 at 17:04
  • It's O(logN), not O(n) time and space complexity for string based solutions. Commented Feb 22, 2022 at 4:03
  • This is O(n) ... Commented Feb 22, 2024 at 5:07