MDIGITS1

I tried many things, but I still get TLE smile
Regards.

from array import array
from sys import stdin, stdout
def mdigits(line):
    line = map(int, line.split())
    occurrences = array('H', [0] * 10)
    if line[0] < line[1]:
    a = line[0]
    b = line[1] + 1
else:
    a = line[1]
    b = line[0] + 1

for number in map(str, range(a, b)):
    for digit in number:
        occurrences[int(digit)] += 1

result = ""
for x in occurrences:
    result += "%d " % x
return result + "\n"
output = []
input = stdin.readlines()
for line in input[:-1]:
    output.append(mdigits(line))
stdout.writelines(output)
  • created

    Aug '09
  • last reply

    Aug '09
  • 1

    reply

  • 140

    views

  • 2

    users

  • 1

    link

Looping from 0 to 100000000 500 times is never going to run in time. You'll need to think of a faster way of counting digits than the naive brute force solution.