[HackerRank][Python3] New Year Chaos
2018. 7. 7. 01:25 |
프로그래밍/HackerRank
Problem :
https://www.hackerrank.com/challenges/new-year-chaos/problem
My Solution :
#!/usr/bin/env python3 def minimumBribes(q): i = -1 memo = {} while i < len(q)-2: i += 1 i = max(0, i) if q[i] == i+1: continue if q[i] > q[i+1]: if memo.setdefault(q[i], 0) == 2: return 'Too chaotic' memo[q[i]] += 1 q[i], q[i+1] = q[i+1], q[i] i -= 2 return sum(memo.values()) t = int(input()) for t_itr in range(t): n = int(input()) q = list(map(int, input().rstrip().split())) result = minimumBribes(q) print(result)
'프로그래밍 > HackerRank' 카테고리의 다른 글
[HackerRank][Python3] Count Triplets (0) | 2018.07.13 |
---|---|
[HackerRank][Python3] Frequency Queries (0) | 2018.07.13 |
[HackerRank][Python3] Sherlock and Anagrams (0) | 2018.07.12 |
[HackerRank][Python3] Array Manipulation (0) | 2018.07.09 |
[HackerRank][Python3] Minimum Swaps 2 (0) | 2018.07.06 |
[HackerRank][Python3] Is This a Binary Search Tree? (2) | 2018.06.25 |
[HackerRank][Python3] Candies (0) | 2018.06.14 |
[HackerRank][Python3] Two Characters (0) | 2018.06.11 |
최근에 달린 댓글 최근에 달린 댓글