Skip to content

BrainOverflowed/CodilityLessons

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codility Lessons Build Status

Codility lessons solutions solved in Swift 4.2

Correctness: 100%🔥

Performance: 100%🔥

Finished lessons:

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

  • FrogJmp: Count minimal number of jumps from position X to Y.
  • PermMissingElem: Find the missing element in a given permutation.
  • TapeEquilibrium: Minimize the value |(A[0] + ... + A[P-1]) - (A[P] + ... + A[N-1])|.

Lesson 4 - Counting Elements

  • 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.
  • MissingInteger: Find the minimal positive integer not occurring in a given sequence.
  • 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

  • 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.
  • CountDiv: Compute number of integers divisible by k in range [a..b].

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

  • MaxSliceSum: Find a maximum sum of a compact subsequence of array elements.
  • MaxProfit: Given a log of stock prices compute the maximum possible earning.
  • MaxDoubleSliceSum: Find the maximal sum of any double slice.

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].
  • Flags: Find the maximum number of flags that can be set on mountain peaks.

Lesson 11 - Sieve of Eratosthenes

  • CountSemiprimes: Count the semiprime numbers in the given range [a..b].
  • CountNonDivisible: Calculate the number of elements of an array that are not divisors of each element.

Lesson 12 - Euclidean algorithm

  • ChocolatesByNumbers: There are N chocolates in a circle. Count the number of chocolates you will eat.
  • CommonPrimeDivisors: Check whether two numbers have the same prime divisors.

Lesson 13 - Fibonacci numbers

  • Ladder: Count the number of different ways of climbing to the top of a ladder.
  • FibFrog: Count the minimum number of jumps required for a frog to get to the other side of a river.

Lesson 14 - Binary search algorithm

  • MinMaxDivision: Divide array A into K blocks and minimize the largest sum of any block.
  • NailingPlanks: Count the minimum number of nails that allow a series of planks to be nailed.

Lesson 15 - Caterpillar method

  • CountDistinctSlices: Count the number of distinct slices (containing only unique numbers).
  • CountTriangles: Count the number of triangles that can be built from a given set of edges.
  • AbsDistinct: Compute number of distinct absolute values of sorted array elements.
  • MinAbsSumOfTwo: Find the minimal absolute value of a sum of two 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.
  • MinAbsSum: Given array of integers, find the lowest absolute sum of elements.

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.
  • 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.
  • TreeProduct: Remove at most two edges from a tree graph to maximize the product of the components' sizes.
  • HilbertMaze: Find the shortest path between two fields in a Hilbert maze.
  • 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.
  • ArrayRecovery: Recover a broken array using partial information in another array.
  • DiamondsCount: Given points on a plane, count the number of sets of four points that form regular diamonds.

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.
  • ArrayInversionCount: Compute number of inversion in an array.
  • PolygonConcavityIndex: Check whether a given polygon in a 2D plane is convex; if not, return the index of a vertex that doesn't belong to the convex hull.

About

Codility lessons solutions solved in Swift 4.2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%