LeetCode 172. Factorial Trailing Zeroes [ Algorithm + Code Explained]

preview_player
Показать описание
Welcome to my channel, where I share my solutions to various coding problems.

In this video, I will explain how to solve the LeetCode question no 172 Factorial Trailing Zeroes. This is a medium-level problem that requires us to find the number of trailing zeroes in the factorial of a given integer n. For example, if n is 5, then 5! = 120, which has one trailing zero.

The main idea behind this solution is to count how many times n can be divided by 5, since each factor of 5 contributes one zero to the factorial. However, we also need to consider the higher powers of 5, such as 25, 125, 625, and so on, as they contribute more than one zero. This can be done by using a loop or a recursion.

The time complexity of this solution is: O(logn)
, The space complexity is O(1)

I hope you found this video helpful and informative. If you did, please give it a thumbs up, share it with your friends, and subscribe to my channel for more coding challenges and solutions.

Thank you for watching and happy coding! 😊
Рекомендации по теме
welcome to shbcf.ru