878910. Divisor

Basic

Divisor

Summary

The problem is about finding all divisors of a given integer. This involves identifying the numbers that can be divided by the original number without leaving a remainder.

Detailed Explanation

The algorithmic approach to this problem is simple: iterate from 1 to the input number and check if the current number is a divisor. A divisor is defined as an integer that divides the original number without leaving a remainder. We can use the modulo operator (%) to perform this check efficiently.

Here's a step-by-step breakdown of the solution:

  1. Initialize an empty list or array to store the divisors.
  2. Iterate from 1 to the input number n.
  3. For each iteration, check if the current number i is a divisor by checking if n % i == 0. If it is, add i to the list of divisors.
  4. Return the list of divisors.

Time complexity: O(n), where n is the input number. This is because we iterate from 1 to n and perform a constant-time operation (checking for divisibility) at each iteration.

Space complexity: O(1), as we only use a constant amount of space to store the list of divisors.

Optimized Solutions

Java

View on GeeksforGeeks
public List<Integer> findDivisors(int n) {
    List<Integer> divisors = new ArrayList<>();
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            divisors.add(i);
        }
    }
    return divisors;
}

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.