[코딜리티] CountNonDivisible
Algorithm 2021. 8. 12. 11:20

▼ 문제 링크 CountNonDivisible coding task - Learn to Code - Codility Calculate the number of elements of an array that are not divisors of each element. app.codility.com 역시나 정답은 맞췄지만, 시간 복잡도에서 실패한 케이스 기존 배열의 값을 새로운 배열의 index로 전환하고 해당 index의 값을 기존 배열의 값의 총 개수로 변환하는 게 풀이의 핵심이었다. 이게 무슨 말이나면 original[i] = k 이고 original배열에서 값 k가 배열 original 내에 전부 n개 있을 때 이 배열을 new배열에 위에서 언급한 방법대로 바꾸면 new[k] = n 이 된다. # 풀..

[코딜리티] MaxDoubleSliceSum
Algorithm 2021. 7. 23. 14:20

▼ 문제 링크 MaxDoubleSliceSum coding task - Learn to Code - Codility Find the maximal sum of any double slice. app.codility.com 문제를 간단하게 정리하면 다음과 같다. 변수 X, Y, Z의 범위: 0 ≤ X < Y < Z < N(배열의 개수) (X, Y, Z)를 이용한 배열의 더블 슬라이스의 합: A[X + 1] + A[X + 2] + ... + A[Y − 1] + A[Y + 1] + A[Y + 2] + ... + A[Z − 1] 일 때, 이 더블 슬라이스의 합이 가질 수 있는 모든 경우의 수 중 최대값을 구하라 # 풀이 1 변수가 3개니까 for문도 3개! import Foundation import Glibc..

[코딜리티] Tape Equilibrium - 시간 복잡도 줄이기
Algorithm 2021. 6. 13. 15:52

▼ 문제 링크 Codility Your browser is not supported You should use a supported browser. Read more app.codility.com # 풀이 1 내가 처음 푼 문제 풀이 func solution(_ A : inout [Int]) -> Int { var left = 0 var right = 0 var index = 0 var result = 0 for i in 1.. 0 index = i repeat { right += A[index] index += 1 } while index abs(left-right) ?..