Find All Divisors of a Number

Implement findDivisors

Given a positive integer n, return every divisor of n — every integer from 1 to n that divides it with no remainder — sorted in ascending order. Divisors always come in pairs: if i divides n, so does n / i. That pairing means you never need to test anything past √n — for every small divisor found on the way up, its larger partner is found for free, without ever touching it directly.

Example 1:

Input: n = 36

Output: [1,2,3,4,6,9,12,18,36]

Example 2:

Input: n = 12

Output: [1,2,3,4,6,12]

Example 3:

Input: n = 7

Output: [1,7]

+ 13 hidden test cases run on Submit.

Constraints:

  • 1 ≤ n ≤ 10⁹

n =

36