https://school.programmers.co.kr/learn/courses/30/lessons/161989 from collections import deque def solution(n, m , section): answer = 0 sectionDeque = deque(section) while sectionDeque: start = sectionDeque.popleft() while sectionDeque and start + m > sectionDeque[0]: sectionDeque.popleft() answer += 1 return answer