Leetcode Problem 1492. The kth Factor of n

1492. The kth Factor of n

Leetcode Solutions

Approach: Math, №(√N) time

  1. Initialize an empty list divisors to store the divisors found.
  2. Iterate x from 1 to √N: a. If x is a divisor of n, append it to divisors. b. If x is a divisor of n, decrement k by 1. c. If k is 0, return x as the kth factor.
  3. If n is a perfect square, increment k by 1 to account for the duplicate divisor.
  4. If k is less than or equal to the length of divisors, return n / divisors[-k] as the kth factor.
  5. If k is greater than the length of divisors, return -1, indicating there are fewer than k factors.
UML Thumbnail

Approach: Brute Force, №(N) time

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...