끄적거림

[HackerRank] Arrays: Left Rotation 본문

Python/알고리즘(코딩테스트)

[HackerRank] Arrays: Left Rotation

Signing 2022. 6. 29. 21:15
728x90
반응형

문제

요약하자면, left rotation operation은 n-size의 array를 왼쪽으로 d만큼 돌리는 연산이다.

 

코드

import collections as co

def rotLeft(a, d):
    dq = co.deque(a)
    dq.rotate(-d)

    return dq

if __name__ == '__main__':
    n = 5
    d = 4
    a = [1,2,3,4,5]

    result = rotLeft(a, d)

    print(result)

해설

  1. collections.deque 두 번 쓰세요~
728x90
반응형

'Python > 알고리즘(코딩테스트)' 카테고리의 다른 글

[HackerRank] New Year Chaos  (0) 2022.06.29
[HackerRank] 2D Array  (0) 2022.06.29
[HackerRank] Repeated String  (0) 2022.06.29
[HackerRank] Jumping on the Clouds  (0) 2022.06.28
[HackerRank] Counting Valleys  (0) 2022.06.28
Comments