codility
-
Codility - TriangleAlgorithm 2022. 11. 15. 16:22
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ Sorting > Triangle์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ ๋๋ณด๊ธฐ An array A consisting of N integers is given. A triplet (P, Q, R) is triangular if 0 ≤ P A[R], A[Q] + A[R] > A[P], A[R] + A[P] > A[Q]. For example, consider array A such that: A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A[5] = 20 Triplet (0, 2, 4) is triangular. Write a function: public func solution(_ A ..
-
Codility - MaxProductOfThreeAlgorithm 2022. 11. 9. 12:24
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ Sorting > MaxProductOfThree์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ ๋๋ณด๊ธฐ A non-empty array A consisting of N integers is given. The product of triplet (P, Q, R) equates to A[P] * A[Q] * A[R] (0 ≤ P < Q < R < N). For example, array A such that: A[0] = -3 A[1] = 1 A[2] = 2 A[3] = -2 A[4] = 5 A[5] = 6 contains the following example triplets: (0, 1, 2), product is −3 * 1 * 2 = −6 (1, 2, 4), product is 1 ..
-
Codility - DistinctAlgorithm 2021. 10. 17. 08:45
์์ฆ ์๊ณ ๋ฆฌ์ฆ์ ๋ํต ์ํ๊ฒ ๊ฐ์์.. ์ฌ์ค ํ ํ์์ฑ์ ํฌ๊ฒ ๋ชป๋๋ผ๊ณ ์์๋๊ฒ๋ ์๋ค๐ฑ ๊ทธ๋์ ์๊ณ ๋ฆฌ์ฆ ํ์ต์ด๋ ๋ฌธ์ ํ์ด๋ฅผ ์์ ๋ณด๋ค ๋ฎ์ ๋น์ค์ผ๋ก ๋๊ธฐ๋ก ํ์์ง๋ง ์ฃผ๋ง์๋ ๋ฅํ๊ฑฐ ํ๊ธฐ๊ฐ ์ซ์ด์ ์ ๋ง ๊ฐ๋จํ๊ฒ ์ฌ์ด๊ฑธ๋ก ๋จธ๋ฆฌ๋ฅผ ๊นจ์ฐ๋ ค๊ณ ์ฌ์ฌํด์ ํ์ด๋ณด๋ ๋ฌธ์ ! ์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ Sorting > distinct์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ Write a function public func solution(_ A : inout [Int]) -> Int that, given an array A consisting of N integers, returns the number of distinct values in array A. For example, given array A consist..
-
ํฉ์ ์ด์ฉํ ์๊ณ ๋ฆฌ์ฆAlgorithm 2021. 8. 29. 11:55
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ Passing Cars์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ A non-empty array A consisting of N integers is given. The consecutive elements of array A represent consecutive cars on a road. Array A contains only 0s and/or 1s: - 0 represents a car traveling east - 1 represents a car traveling west. The goal is to count passing cars. We say that a pair of cars (P, Q), where 0 ≤ P < Q < N, is passing when P is..
-
์ํ๋ฅผ ์ต์ํํ ์๊ณ ๋ฆฌ์ฆ (2)Algorithm 2021. 8. 1. 10:53
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ MissingInteger์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ This is a demo task. Write a function: public func solution(_ A : inout [Int]) -> Int that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5. Given A = [1, 2, 3], the function should return 4. Given A = [−1, −3]..
-
์ํ๋ฅผ ์ต์ํํ ์๊ณ ๋ฆฌ์ฆAlgorithm 2021. 7. 24. 11:29
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ MaxCounters์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max counter − all counters are set to the maximum value of any counter. A non-empty array A of M integers is given. This array represents consecutive operations: if A[K] = X, such that 1 ≤ X ≤ N, then operation K is..
-
FlogRiverOne ์๊ณ ๋ฆฌ์ฆAlgorithm 2021. 7. 18. 10:45
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ FlogRiverOne์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ A small frog wants to get to the other side of a river. The frog is initially located on one bank of the river (position 0) and wants to get to the opposite bank (position X+1). Leaves fall from a tree onto the surface of the river. You are given an array A consisting of N integers representing the falling leaves. A[K] represents the position wher..
-
์๊ฐ๋ณต์ก๋๋ฅผ ๊ณ ๋ คํ ์๊ณ ๋ฆฌ์ฆ (3)Algorithm 2021. 7. 11. 13:50
์๋ ๋ฌธ์ ๋ ์ฝ๋๋ฆฌํฐ์์ ์ ๊ณตํ๋ TapeEquilibrium์ ๋ฌธ์ ์ ๋๋ค๐ง๐ป๐ป ๋ฌธ์ ์ ์ A non-empty array A consisting of N integers is given. Array A represents numbers on a tape. Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N − 1]. The difference between the two parts is the value of: |(A[0] + A[1] + ... + A[P − 1]) − (A[P] + A[P + 1] + ... + ..