Skip to content

Instantly share code, notes, and snippets.

@sAVItar02
Created November 16, 2024 12:20
Show Gist options
  • Save sAVItar02/6584d2ab5d85ca302b90c0934da991b8 to your computer and use it in GitHub Desktop.
Save sAVItar02/6584d2ab5d85ca302b90c0934da991b8 to your computer and use it in GitHub Desktop.
Factorial Trailing Zeroes
/**
* @param {number} n
* @return {number}
*/
var trailingZeroes = function(n) {
let x = 5;
let zeroes = 0;
while((n/x) >= 1) {
zeroes += Math.floor(n / x);
x = x * 5;
}
return zeroes;
};
// GRE Math thingy
// Time: O(log(n))
// Space: O(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment