You are given an integer n. Your task is to break it down into its decimal components and return them as an array.
For example:
n = 4321 → [4000, 300, 20, 1]n = 5030 → [5000, 30]n = 7 → [7]Return the decimal representation as an array of integers, excluding zeros.
1 <= n <= 10^9Extract each non-zero digit and multiply it by its place value, starting from the units place.
Algorithm:
place = 1 (units place)n > 0:
    digit = n % 10digit * place and add to listn = n / 10place = place * 10This approach works because:
Example 1: n = 5030
Step-by-step execution:
List before reverse: [30, 5000]
List after reverse: [5000, 30]
Result: [5000, 30]
Example 2: n = 4321
Step-by-step execution:
List before reverse: [1, 20, 300, 4000]
List after reverse: [4000, 300, 20, 1]
Result: [4000, 300, 20, 1]
Example 3: n = 7
Step-by-step execution:
List before reverse: [7]
List after reverse: [7]
Result: [7]
class Solution {
    public int[] decimalRepresentation(int n) {
        List<Integer> base = new ArrayList<>();
        int place = 1;
        while (n > 0) {
            int digit = n % 10;
            if (digit != 0) {
                base.add(digit * place);
            }
            n /= 10;
            place *= 10;
        }
        Collections.reverse(base);
        int[] list = new int[base.size()];
        for (int i = 0; i < base.size(); i++) {
            list[i] = base.get(i);
        }
        return list;
    }
}
class Solution {
    public int[] decimalRepresentation(int n) {
        String s = String.valueOf(n);
        List<Integer> result = new ArrayList<>();
        for (int i = s.length() - 1; i >= 0; i--) {
            int digit = s.charAt(i) - '0';
            if (digit != 0) {
                int placeValue = digit * (int) Math.pow(10, s.length() - 1 - i);
                result.add(placeValue);
            }
        }
        return result.stream().mapToInt(Integer::intValue).toArray();
    }
}
Explanation: Convert to string and calculate place values using powers of 10.
Time Complexity: O(log₁₀ n) - string conversion and processing Space Complexity: O(log₁₀ n) - for string and result list
class Solution {
    public int[] decimalRepresentation(int n) {
        List<Integer> result = new ArrayList<>();
        int multiplier = 1;
        while (n > 0) {
            int remainder = n % 10;
            if (remainder != 0) {
                result.add(remainder * multiplier);
            }
            n = n / 10;
            multiplier = multiplier * 10;
        }
        // Reverse the list
        Collections.reverse(result);
        return result.stream().mapToInt(Integer::intValue).toArray();
    }
}
Explanation: Same logic but with different variable names for clarity.
Time Complexity: O(log₁₀ n) - digit processing Space Complexity: O(log₁₀ n) - result storage
class Solution {
    private List<Integer> result = new ArrayList<>();
    public int[] decimalRepresentation(int n) {
        helper(n, 1);
        Collections.reverse(result);
        return result.stream().mapToInt(Integer::intValue).toArray();
    }
    private void helper(int n, int place) {
        if (n == 0) return;
        int digit = n % 10;
        if (digit != 0) {
            result.add(digit * place);
        }
        helper(n / 10, place * 10);
    }
}
Explanation: Use recursion to process digits from least significant to most significant.
Time Complexity: O(log₁₀ n) - recursive calls for each digit Space Complexity: O(log₁₀ n) - recursion stack + result list
Place Value System:
Why Skip Zeros:
[5000, 0, 30] instead of [5000, 30]Edge Cases:
n = 1 → [1]n = 10 → [10] (not [10, 0])n = 100 → [100] (not [100, 0, 0])n = 101 → [100, 1] (not [100, 0, 1])Applications: