344A: Time limit exceeds on test #7

Revision en1, by dashrath1526, 2020-08-19 08:54:32

Getting a time limit exceeds error on test #7. Help and understanding of efficient solution would be well appreciated.

n = int(input())
string = ''
group_count = 0
for i in range(n):
    num = input()

    if i == 0 or num[0] == string[-1]:
        string += num     
        group_count += 1
    else:
        string += num

print(group_count)
Tags 344a, magnets

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English dashrath1526 2020-08-19 08:54:32 416 Initial revision (published)