DEV Community

Md. Rishat Talukder
Md. Rishat Talukder

Posted on

🧠 Solving LeetCode Until I Become Top 1% β€” Day `77`

πŸ”Ή Problem: 1317 Convert Integer to the Sum of Two No-Zero Integers

Difficulty: #Easy
Tags: #Math, #BruteForce


πŸ“ Problem Summary

We are given an integer n. We need to split it into two positive integers A and B such that:

  1. A + B = n
  2. Neither A nor B contains the digit 0.

Return any valid pair [A, B].


🧠 My Thought Process

  • Brute Force Idea:
    Iterate over all possible values of A from 1 to n-1. For each A, compute B = n - A.
    Check if both numbers do not contain the digit 0.

  • Optimized Strategy:
    Since the range is only 1 to n-1, the brute force is actually fine. The constraint is small enough that this simple approach passes.

  • Algorithm Used:
    Simple brute force search with string conversion to detect 0.


βš™οΈ Code Implementation (Python)

class Solution:
    def getNoZeroIntegers(self, n: int) -> List[int]:
        for A in range(1, n):
            B = n - A
            if "0" not in str(A) + str(B):
                return [A, B]
        return []
Enter fullscreen mode Exit fullscreen mode

⏱️ Time & Space Complexity

  • Time: O(n * log(n))
    (We loop up to n, and string conversion/checking costs about O(log n) per number.)

  • Space: O(1)
    (Only a few integers are stored at a time.)


🧩 Key Takeaways

  • βœ… Checking digits via string conversion is often the simplest and fast enough for small constraints.
  • πŸ’‘ Sometimes brute force is the intended solution when constraints are low.
  • πŸ’­ Always confirm input size before over-optimizing.

πŸ” Reflection (Self-Check)

  • [x] Could I solve this without help?
  • [x] Did I write code from scratch?
  • [x] Did I understand why it works?
  • [x] Will I be able to recall this in a week?

πŸš€ Progress Tracker

Metric Value
Day 77
Total Problems Solved 441
Confidence Today πŸ˜ƒ
Leetcode Rating 1530

Top comments (0)