코딩테스트 파이썬/hackerrank
Breaking the Records
세용용용용
2024. 9. 1. 20:51
https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem?isFullScreen=true
Breaking the Records | HackerRank
Given an array of Maria's basketball scores all season, determine the number of times she breaks her best and worst records.
www.hackerrank.com
나의 코드
#!/bin/python3
import math
import os
import random
import re
import sys
def breakingRecords(scores):
answer = [0,0]
h_est = scores[0]
l_est = scores[0]
for i in range(1, len(scores)):
now_score = scores[i]
if now_score>h_est:
answer[0]+=1
h_est=now_score
elif now_score<l_est:
answer[1]+=1
l_est=now_score
return answer
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
scores = list(map(int, input().rstrip().split()))
result = breakingRecords(scores)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()
시간 복잡도
for i in range(1, len(scores)) : scores 점수 리스트를 순회하므로 선형 시간 복잡도
즉, 해당 알고리즘 시간 복잡도는 선형 시간 복잡도 ( O(n) )