Sort by

recency

|

1622 Discussions

|

  • + 0 comments

    Tried this but it is too slow, it failed two tests due to timeout. Any suggestions on what is the bottleneck and how to speed it up?

    n_words = int(input())
    
    word_list = []
    occurrence_list = []
    
    for i in range(n_words):
    
    word = input()
    
    try:
        idx = word_list.index(word)
        occurrence_list[idx] += 1
    except:
        word_list.append(word)
        occurrence_list.append(1)
    

    print(len(word_list)) print(' '.join(map(str, occurrence_list)))

  • + 0 comments
    from collections import Counter
    n= int(input())
    words= Counter([input() for _ in range(n)])
    print(len(words.keys()))
    print(*words.values())
    
  • + 0 comments
    n = int(input())
    
    dic = {}
    
    for _ in range(n):
        word = input()
        if word in dic.keys():
            dic[word]+=1
        else:
            dic[word] = 1
    
    print(len(dic.keys()))
    
    occ = [str(i) for i in dic.values()]
    
    print(' '.join(occ))
    
  • + 0 comments

    from collections import Counter

    n = int(input()) cnt = Counter()

    for _ in range(n): cnt[input()] += 1

    print(len(cnt)) print(*[cnt[i] for i in cnt])

  • + 0 comments
    N = int(input())
    dicts = {}
    orders = []
    
    for _ in range(N):
        orders.append(str(input()))
        
        if orders[_] not in dicts:
            dicts[orders[_]] = 1
        else:
            dicts[orders[_]] += 1
            
    print(len(set(orders)))
    
    print(" ".join(map(str, dicts.values())))