DevYoon

[ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€] ν˜Έν…” λŒ€μ‹€ (Python) λ³Έλ¬Έ

PS/Programmers

[ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€] ν˜Έν…” λŒ€μ‹€ (Python)

gimewn 2023. 2. 3. 18:44

link πŸ”— https://school.programmers.co.kr/learn/courses/30/lessons/155651

 

ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€

μ½”λ“œ μ€‘μ‹¬μ˜ 개발자 μ±„μš©. μŠ€νƒ 기반의 ν¬μ§€μ…˜ 맀칭. ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€μ˜ 개발자 λ§žμΆ€ν˜• ν”„λ‘œν•„μ„ λ“±λ‘ν•˜κ³ , λ‚˜μ™€ 기술 ꢁ합이 잘 λ§žλŠ” 기업듀을 맀칭 λ°›μœΌμ„Έμš”.

programmers.co.kr

 

문제 μ„€λͺ…

ν˜Έν…”μ„ 운영 쀑인 μ½”λ‹ˆλŠ” μ΅œμ†Œν•œμ˜ κ°μ‹€λ§Œμ„ μ‚¬μš©ν•˜μ—¬ μ˜ˆμ•½ μ†λ‹˜λ“€μ„ λ°›μœΌλ €κ³  ν•©λ‹ˆλ‹€. ν•œ 번 μ‚¬μš©ν•œ 객싀은 퇴싀 μ‹œκ°„μ„ κΈ°μ€€μœΌλ‘œ 10λΆ„κ°„ μ²­μ†Œλ₯Ό ν•˜κ³  λ‹€μŒ μ†λ‹˜λ“€μ΄ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
μ˜ˆμ•½ μ‹œκ°μ΄ λ¬Έμžμ—΄ ν˜•νƒœλ‘œ λ‹΄κΈ΄ 2차원 λ°°μ—΄ book_time이 λ§€κ°œλ³€μˆ˜λ‘œ μ£Όμ–΄μ§ˆ λ•Œ, μ½”λ‹ˆμ—κ²Œ ν•„μš”ν•œ μ΅œμ†Œ κ°μ‹€μ˜ 수λ₯Ό return ν•˜λŠ” solution ν•¨μˆ˜λ₯Ό μ™„μ„±ν•΄μ£Όμ„Έμš”.

 

μ œν•œμ‚¬ν•­

  • 1 ≤ book_time의 길이 ≤ 1,000
    • book_time[i]λŠ” ["HH:MM", "HH:MM"]의 ν˜•νƒœλ‘œ 이루어진 λ°°μ—΄μž…λ‹ˆλ‹€
      • [λŒ€μ‹€ μ‹œμž‘ μ‹œκ°, λŒ€μ‹€ μ’…λ£Œ μ‹œκ°] ν˜•νƒœμž…λ‹ˆλ‹€.
    • μ‹œκ°μ€ HH:MM ν˜•νƒœλ‘œ 24μ‹œκ°„ ν‘œκΈ°λ²•μ„ λ”°λ₯΄λ©°, "00:00" λΆ€ν„° "23:59" κΉŒμ§€λ‘œ μ£Όμ–΄μ§‘λ‹ˆλ‹€.
      • μ˜ˆμ•½ μ‹œκ°μ΄ μžμ •μ„ λ„˜μ–΄κ°€λŠ” κ²½μš°λŠ” μ—†μŠ΅λ‹ˆλ‹€.
      • μ‹œμž‘ μ‹œκ°μ€ 항상 μ’…λ£Œ μ‹œκ°λ³΄λ‹€ λΉ λ¦…λ‹ˆλ‹€.

 


 

πŸ”₯ λŒ€μ‹€ μ‹œμž‘ μ‹œκ°„κ³Ό μ’…λ£Œ μ‹œκ°„μ„ λΆ„ λ‹¨μœ„λ‘œ λ³€ν™˜

πŸ”₯ λˆ„μ ν•©μ„ ν™œμš©ν•΄μ„œ ν’€κΈ°! μ‹œκ°„μ΄ κ°€μž₯ 많이 겹친 μˆ˜κ°€ μ΅œμ†Œ λ°© κ°œμˆ˜κ°€ λœλ‹€.

 

def solution(book_time):
    rooms = [0]*((24*60)+10)
    
    for book in book_time:
        # λŒ€μ‹€ μ‹œκ°„ λΆ„ λ‹¨μœ„ λ³€ν™˜
        start, end = book[0], book[1]
        shour, sminute = map(int, start.split(":"))
        ehour, eminute = map(int, end.split(":"))
        cal_s = shour*60+sminute
        cal_e = ehour*60+eminute
        # λŒ€μ‹€ μ‹œμž‘ μ‹œκ°„μ— +1
        rooms[cal_s] += 1
        # λŒ€μ‹€ μ’…λ£Œ μ‹œκ°„ + μ²­μ†Œ μ‹œκ°„(10)에 -1
        rooms[cal_e+10] -= 1
        
    # λˆ„μ ν•© 계산
    for idx in range(1, (24*60)+10):
        rooms[idx] += rooms[idx-1]
    
    return max(rooms)