Separate the Numbers

  • + 1 comment

    Python 3: we can sove this question in 2 ways. one: is by adding into substr and second: is calculation difference of 1. Mine is from type one in O(n).

    def separateNumbers(s):
        loop_limit = len(s)//2
    
        substr = ""
        min_value = 0
        found = False
    
        for i in range(1, loop_limit + 1):
            slice_str = s[:i]
            temp = int(slice_str)
            min_value = temp
            substr = slice_str 
             
            while len(substr) < len(s):
                temp += 1
                substr += str(temp)
                
                if substr == s:
                    print("YES", min_value)
                    found = True
                    break
                
        if found == False:
          print("NO")