The problem requires counting amazing performances where a contestant's score breaks their
previous records. We initialize
minScore and
maxScore with the first
contest's score. For each subsequent score, we check if it either
exceeds maxScore or
falls below minScore.
When either condition is met, we update the corresponding extreme value
and increment our amazingCount.
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 uses a constant amount of extra space, regardless of the input size.