803. Factors of a Given Number

Given a natural number n, return a list of all distinct positive integers that are factors (divisors) of n in increasing order.

Example 1:

Input: n = 6  

Output: [1, 2, 3, 6]  

Explanation: 6 is divisible by 1, 2, 3, and 6.

Example 2:

Input: n = 9  

Output: [1, 3, 9]  

Explanation: 9 is divisible by 1, 3, and 9.

Now Your Turn!

Pick the correct output for the given input

Input: n = 28  

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n <= 109
  • The output must be in increasing order
  • You must not use extra space proportional to n
0
class Solution {
public:
vector<int> findFactors(int n) {
// Your code goes here
}
};
Test Case

Input:

N