0

I wrote some code for a HackerRank problem (https://www.hackerrank.com/challenges/acm-icpc-team).

import time
from itertools import combinations

start_time = time.time()

n,m = raw_input().strip().split(' ') # n = no of people and m = no of topics
n,m = [int(n),int(m)]
topic = []
topic_i = 0
for topic_i in xrange(n):
   topic_t = str(raw_input().strip())
   topic.append(topic_t)    # populate the topic[] list with the topics

counts = []
for list1, list2 in combinations(topic, 2):
   if list1 != list2:
      count = 0
      for i in xrange(m):
        if int(list1[i]) | int(list2[i]):
            count += 1
      counts.append(count)

print max(counts)
print counts.count(max(counts))

print time.time() - start_time

When I try to run the code, I get an execution time of 8.37576699257 seconds. But my program got over in a jiffy. I have read that the timeit() function, by default, runs the function passed to it a million times. Does something similar happen here?

1
  • Okay, will use it the next time I want to time my program. Commented Mar 17, 2016 at 11:20

1 Answer 1

4

You counted the time when the program waited for the user input too. You may want to move the first time.time() invocation below raw_input().

Sign up to request clarification or add additional context in comments.

1 Comment

Oh yeah, thanks! Didn't see that. It now takes 0.00075888633728 seconds. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.