Created
July 31, 2023 14:30
-
-
Save thekhairul/7ab54aa99311c9b9cc6138684467fb95 to your computer and use it in GitHub Desktop.
a function to calculate the sum of the first N natural numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sumOfFirstN(n) { | |
return (n*(n+1)) / 2; | |
} | |
// Time complexity - O(1) | |
// Space complexity - O(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment