FrogRiverOne Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(X, A): # write your code in Python 3.6 position = set() for i, a in enumerate(A): if a = X: return i return -1 Codility/Easy 2022.05.15
PermCheck Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A): # write your code in Python 3.6 permutation = [i for i in range(0, len(A) + 1)] for a in A: if a >= len(permutation): return 0 permutation[a] = 0 return 0 if len([i for i in permutation if i != 0]) > 0 else 1 Codility/Easy 2022.05.15
TapeEquilibrium Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A): # write your code in Python 3.6 total = sum(A) pre_total = 0 min_diff = abs(total - A[0] * 2) for v in A[:-1]: total -= v pre_total += v min_diff = min(abs(pre_total - total), min_diff) return min_diff Codility/Easy 2022.05.13
PermMissingElem Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A): # write your code in Python 3.6 A.sort() number = 1 for i, v in enumerate(A): if v != number: return number number += 1 return number Codility/Easy 2022.05.12
FrogJmp Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(X, Y, D): # write your code in Python 3.6 result = (Y - X) // D result += 1 if (Y - X) % D > 0 else 0 return result Codility/Easy 2022.05.11
OddOccurrencesInArray Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A): # write your code in Python 3.6 A.sort() for i in range(0, len(A) - 1, 2): if A[i] != A[i + 1]: return A[i] return A[-1] Codility/Easy 2022.05.10
BinaryGap Python # you can write to stdout for debuggin def solution(N): # write your code in Python 3.6 number_str = bin(N)[2:] number_arr = number_str.split("1") if number_arr[-1] != "": return 0 l = [len(v) for v in number_arr if number_arr] if len(l) == 0: return 0 return max(l) Codility/Easy 2022.05.09
CyclicRotation Python # you can write to stdout for debugging purposes, e.g. # print("this is a debug message") def solution(A, K): # write your code in Python 3.6 if K == 0 or len(A) == 0: return A K = K % len(A) return A[len(A) - K:] + A[:len(A) - K] Codility/Easy 2022.05.08