Codility lessons solutions solved in Swift 4
Correctness: 💯🔥%
Performance: 💯🔥%
Lesson 1 - Iterations
- BinaryGap: Find longest sequence of zeros in binary representation of an integer.
Lesson 2 - Arrays
- OddOccurrencesInArray: Find value that occurs in odd number of elements.
- CyclicRotation: Rotate an array to the right by a given number of steps.
Lesson 3 - Time Complexity
- PermMissingElem: Find the missing element in a given permutation.
- FrogJmp: Count minimal number of jumps from position X to Y.
- TapeEquilibrium: Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|.
Lesson 4 - Counting Elements
- MissingInteger: Find the minimal positive integer not occurring in a given sequence.
- PermCheck: Check whether array A is a permutation.
- FrogRiverOne: Find the earliest time when a frog can jump to the other side of a river.
- MaxCounters: Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.
Lesson 5 - Prefix Sums
- CountDiv: Compute number of integers divisible by k in range [a..b].
- PassingCars: Count the number of passing cars on the road.
- GenomicRangeQuery: Find the minimal nucleotide from a range of sequence DNA.
- MinAvgTwoSlice: Find the minimal average of any slice containing at least two elements.
Lesson 6 - Sorting
- Distinct: Compute number of distinct values in an array.
- MaxProductOfThree: Maximize A[P] * A[Q] * A[R] for any triplet (P, Q, R).
- Triangle: Determine whether a triangle can be built from a given set of edges.
- NumberOfDiscIntersections: Compute the number of intersections in a sequence of discs.
Lesson 7 - Stacks and Queues
- Brackets: Determine whether a given string of parentheses is properly nested.
- Fish: N voracious fish are moving along a river. Calculate how many fish are alive.
- Nesting: Determine whether given string of parentheses is properly nested.
- StoneWall: Cover "Manhattan skyline" using the minimum number of rectangles.
Lesson 8 - Leader
- EquiLeader: Find the index S such that the leaders of the sequences A[0], A[1], ..., A[S] and A[S + 1], A[S + 2], ..., A[N - 1] are the same.
- Dominator: Find an index of an array such that its value occurs at more than half of indices in the array.
Lesson 9 - Maximum slice problem
- MaxDoubleSliceSum: Find the maximal sum of any double slice.
- MaxProfit: Given a log of stock prices compute the maximum possible earning.
- MaxSliceSum: Find a maximum sum of a compact subsequence of array elements.
Lesson 10 - Prime and composite numbers
- CountFactors: Count factors of given number n.
- MinPerimeterRectangle: Find the minimal perimeter of any rectangle whose area equals N.
- Peaks: Divide an array into the maximum number of same-sized blocks, each of which should contain an index P such that A[P - 1] < A[P] > A[P + 1].
Lesson 11 - Sieve of Eratosthenes
Lesson 12 - Euclidean algorithm
Lesson 13 - Fibonacci numbers
Lesson 14 - Binary search algorithm
Lesson 15 - Caterpillar method
- AbsDistinct: Compute number of distinct absolute values of sorted array elements.
Lesson 16 - Greedy algorithms
- MaxNonoverlappingSegments: Find a maximal set of non-overlapping segments.
- TieRopes: Tie adjacent ropes to achieve the maximum number of ropes of length >= K.
Lesson 17 - Dynamic programming
- NumberSolitaire: In a given array, find the subset of maximal sum in which the distance between consecutive elements is at most 6.
Lesson 90 - Tasks from Indeed Prime 2015 challenge
- LongestPassword: Given a string containing words, find the longest word that satisfies specific conditions.
- FloodDepth: Find the maximum depth of water in mountains after a huge rainfall.
Lesson 91 - Tasks from Indeed Prime 2016 challenge
- DwarfsRafting: Find out how many dwarfs can fit on a raft such that it's balanced when crossing a river.
Lesson 92 - Tasks from Indeed Prime 2016 College Coders challenge
- TennisTournament: Given the numbers of players and available courts, calculate the maximum number of parallel tennis games.
- SocksLaundering: From drawers containing both clean and dirty socks, choose socks to launder in order to obtain the maximum number of clean pairs of socks.
Lesson 99 - Future training
- SqlSum: Calculate sum of elements.
- StrSymmetryPoint: Find a symmetry point of a string, if any.
- TreeHeight: Compute the height of a binary tree.
Lesson 10 - Prime and composite numbers
Lesson 12 - Euclidean algorithm
- ChocolatesByNumbers: There are N chocolates in a circle. Count the number of chocolates you will eat.
Lesson 90 - Tasks from Indeed Prime 2015 challenge
- SlalomSkiing: Given a sequence, find the longest subsequence that can be decomposed into at most three monotonic parts.
Lesson 91 - Tasks from Indeed Prime 2016 challenge
- RectangleBuilderGreaterArea: Count the distinct rectangle sizes, of area greater than or equal to X, that can be built out of a given set of segments.
Lesson 99 - Future training
- ArrayInversionCount: Compute number of inversion in an array.