기타/Codility

[Easy] MaxNonoverlappingSegments

백곰곰 2022. 6. 7. 21:16
728x90
반응형

[문제]

주어진 선의 좌표 중 서로 겹치지 않는 좌표들의 조합의 최대수를 찾는 문제

 

MaxNonoverlappingSegments coding task - Learn to Code - Codility

Find a maximal set of non-overlapping segments.

app.codility.com

 

[코드]

시간복잡도 : O(N)

def solution(A, B):
    # write your code in Python 3.6
    if not A:
        return 0
    standard = B[0]
    answer=1
    for idx, a in enumerate(A) :
        if idx==0 :
            continue
        else :
            if a > standard :
                answer=answer+1
                standard=B[idx]
    return answer
728x90

'기타 > Codility' 카테고리의 다른 글

[Easy] OddOccurencesInArray  (0) 2022.06.07
[Easy] Triangle  (0) 2022.06.07
[Elementary] ParkingBill  (0) 2022.06.07
[Easy] ChocolatesByNumbers  (0) 2022.06.06
[Easy] MaxProductOfThree  (0) 2022.06.06