The problem requires counting amazing performances where a contestant's score breaks their
previous records. We initialize
min_score and
max_score with the first
contest's score. For each subsequent score, we check if it either
exceeds max_score or
falls below min_score.
When either condition is met, we update the corresponding extreme value
and increment our amazing_count.
def main(): n = int(input()) scores = list(map(int, input().split())) max_score = scores[0] min_score = scores[0] amazing_count = 0 for score in scores[1:]: if score > max_score: max_score = score amazing_count += 1 elif score < min_score: min_score = score amazing_count += 1 print(amazing_count) if __name__ == "__main__": main()
The algorithm iterates through the array of scores once, making it linear in time complexity.
The algorithm stores all the scores in a list (and slicing creates a copy of it), so the extra space is proportional to the number of contests.