2022/05 16

[Easy] CountFactors

[문제] 주어진 수의 모든 약수의 개수를 구하는 문제 CountFactors coding task - Learn to Code - Codility Count factors of given number n. app.codility.com [코드] N이 큰 값으로 주어지기 때문에 시간복잡도가 O(N)라면 timeout이 발생한다. 제곱근의 약수의 개수를 구하여 해당 값을 활용한다. import math def solution(N): # write your code in Python 3.6 sqrt_value = math.sqrt(N) answer= 0 i = 1 while i < sqrt_value : if N%i == 0: answer = answer + 1 i = i+1 answer = answer*2 ..

기타/Codility 2022.05.30

[Easy] MaxProfit

[문제] 배열 내 각 날짜 별 물건 가격이 주어지고, 과거에 산 물건을 팔았을 때 최대 이윤을 찾는 문제 MaxProfit coding task - Learn to Code - Codility Given a log of stock prices compute the maximum possible earning. app.codility.com [코드] 최소 가격과 최대 이윤을 저장함 def solution(A): # write your code in Python 3.6 if len(A) >= 1 : min_price = min(A[0], A[1]) answer = A[1] - A[0] for i in A[2:len(A)] : min_price = min(min_price, i) answer = max(ans..

기타/Codility 2022.05.30

[Easy] Dominator

[문제] 전체 배열의 중에서 절반 이상 반복되어 나타나는 숫자가 있는지 찾고 있다면 그 숫자의 index를 리턴하는 문제 Dominator coding task - Learn to Code - Codility Find an index of an array such that its value occurs at more than half of indices in the array. app.codility.com [코드] Dictionary를 이용해 값 별로 등장 횟수를 카운팅 함 시간복잡도 : O(N*log(N)) or O(N) def solution(A): # write your code in Python 3.6 max = 0 max_val = 0 dict= {} for i in A : if dict.ge..

기타/Codility 2022.05.26

[Easy] Fish

[문제] 서로 움직이는 방향이 다른 물고기들이 마주쳤을 때 물고기 크기에 따라 작은 물고기는 죽고 큰 물고기만 살아남을 때 전체적으로 살아남는 물고기 수를 세는 문제 Fish coding task - Learn to Code - Codility N voracious fish are moving along a river. Calculate how many fish are alive. app.codility.com [코드] Stack에 downstream으로 움직이는 물고기를 담고 크기를 비교하여 살아 남는 물고기 수를 카운팅 함 시간복잡도 : O(N) def solution(A, B): # write your code in Python 3.6 fish = [] answer = 0 for idx, f in ..

기타/Codility 2022.05.26

[Easy] PassingCars

[문제] 동쪽으로 움직이는 차와 서쪽으로 움직이는 차에 대한 정보가 배열로 주어지고 도로에서 서로 지나치는 차의 쌍(pair)을 구하는 문제 https://app.codility.com/programmers/lessons/5-prefix_sums/passing_cars/ PassingCars coding task - Learn to Code - Codility Count the number of passing cars on the road. app.codility.com [코드] 풀이 : 배열 내 모든 수가 0과 1로 이루어져 있기에 전체 합을 구하고 배열 값이 0인 index 이후의 부분 배열의 합을 구하여 더하는 방식 시간복잡도 : O(N) # you can write to stdout for deb..

기타/Codility 2022.05.24

EFK Stack 구성하기 (Amazon OpenSearch + FluentBit + Kibana)

Kubernetes 내 컨테이너의 로그 수집에는 다양한 방법이 있습니다. 구성 조합에 따라 ELK, EFK 등이 있고, Amazon EKS 구성 시에는 Container Insights를 통해 CloudWatch에 로그를 게시할 수 있습니다. 그 중 AWS for Fluent Bit 이미지를 사용하지 못하는 경우에 fluentbit과 Amazon OpenSearch Service를 활용하여 EFK를 구성해보겠습니다. 현재 EKS Anywhere에서는 AWS for Fleunt Bit 이미지 사용 시 metadata를 찾지 못해 정상적으로 컨테이너를 구동할 수 없습니다. [목표] [기본 환경] Internet Outbound 통신이 가능한 Kubernetes Cluster [배포 순서] 1. IAM Use..

Kubernetes 2022.05.23

[Easy] FrogJmp

[문제] 현재 위치(X), 점프 거리(D), 목표지점(Y) 현재 위치로부터 목표지점에 도달/지나칠 때까지 몇번의 점프를 해야하는지 찾는 문제 FrogJmp coding task - Learn to Code - Codility Count minimal number of jumps from position X to Y. app.codility.com [코드] # 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 count=Y-X if count==0: return 0 i = int(count/D) j = ..

기타/Codility 2022.05.22
반응형