• + 0 comments
    def solve(n):
        queue = deque(['9'])
        visited = set()
        
        while queue:
            current = queue.popleft()
            
            current_num = int(current)
            
            if current_num % n == 0:
                return current
                
            next_num1 = current + '0'
            next_num2 = current + '9'
            
            if next_num1 not in visited:
                queue.append(next_num1)
                visited.add(next_num1)
                
            if next_num2 not in visited:
                queue.append(next_num2)
                visited.add(next_num2)