Giter VIP home page Giter VIP logo

codility's Introduction

Codility Solutions

Lessons

Here are my solutions to the codility lessons. You can find the lessons here.

Details Legend: D = Difficulty; TS = Task Score; C = Completeness; P = Performance; TC = Time Complexity

Task - Solution Details
Lesson 1 - Iterations
BinaryGap.cpp
Lesson 2 - Arrays
CyclicRotation.cpp
OddOccurencesInArray.cpp
Lesson 3 - Time Complexity
PermMissingElem.cpp
FrogJmp - FrogJmp.cpp
TapeEquilibrium.cpp
Lesson 4 - Counting Elements
PermCheck.cpp
FrogRiverOne.cpp
MaxCounters.cpp
MissingInteger.cpp
Lesson 5 - Prefix Sums
PassingCars.cpp
GenomicRangeQuery.cpp
MinAvgTwoSlice.cpp
CountDiv.cpp
Lesson 6 - Sorting
Distinct.cpp
Triangle.cpp
MaxProductOfThree.cpp
NumberOfDiscIntersections
Lesson 7 - Stacks and Queues
Brackets.cpp
Nesting.cpp
StoneWall.cpp
Fish.cpp
Lesson 8 - Leader
EquiLeader.cpp
Dominator.cpp
Lesson 9 - Maximum Slice Problem
MaxSliceSum.cpp
MaxProfit.cpp
MaxDoubleSliceSum
Lesson 10 - Prime and Composite Numbers
CountFactors.cpp
MinPerimeterRectangle.cpp
Peaks
Flags
Lesson 11 - Sieve Of Eratosthenes
CountNonDivisible.cpp
CountSemiprimes
Lesson 12 - Euclidean Algorithm
ChocolatesByNumbers.cpp
CommonPrimeDivisors
Lesson 13 - Fibonacci Numbers
FibFrog.cpp
Ladder
Lesson 14 - Binary Search Algorithm
MinMaxDivision.cpp
NailingPlanks.cpp
Lesson 15 - Caterpillar Method
AbsDistinct.cpp
CountDistinctSlices.cpp
CountTriangles.cpp
MinAbsSumOfTwo
Lesson 16 - Greedy Algorithms
MaxNonoverlappingSegments.cpp
TieRopes.cpp
Lesson 17 - Dynamic Programming
NumberSolitaire
MinAbsSum

Tests

Assuming you are using cmake, tests will be located in your $BUILD_DIR}/bin directory. All tests are in the same codility binary. Individual tests can be run per the googletest framework documentation. Here is a quick reference:

/path/to/build/bin> codility --help
/path/to/build/bin> codility --gtest_list_tests
/path/to/build/bin> codility --gtest_filter=TestName.Test
/path/to/build/bin> codility --seed 12345

Dependencies

Test are built using the following packages. Use CMake and the dependencies will be downloaded and built for you.

Building

You can build the tests for your favorite development environment using cmake. e.g.:

  • For the command line:
mkdir test/build
cd test/build
cmake ..
make
  • For XCode:
mkdir test/xcode
cd test/xcode
cmake -G Xcode ..
make

Tests will be created in the bin directory located wherever you ran cmake from (test\build\bin in the example above).

Contributing

You are welcome to contribute provided you accept the Contributor Covenant Code of Conduct. Also, please do the following:

  • Submit a pull request. In the PR, Tell me how you figured out what you figured out. Links and background are very much appreciated (e.g. I used the binomial distribution found here. This is commonly used to solve this class of problem because my professor told me...). Remember, part of this code base is to educate.
  • Sign your commits.
  • Comment your code!
  • Look at the other source files and follow the same general style and naming conventions. Most importantly, use meaningful variable names, e.g.
    • bad example: int a, aa, a1, a1a, aaaaa;
    • good example: int a, b, average, numDogs, temperature;
  • Learn and use my test methodology. For function.cpp, I create functionTest.cpp with a solution() and bruteForce() method. Please use this when it makes sense. Simple solutions probably don't need it. If you are optimizing one of my methods that I couldn't figure out, please use the test methodology.

License

This repository is licensed under The Unlicense.

Acknowledgements

  • Thank you to the gflags command line parsing library.
  • Thank you to the googletest C++ test framework.
  • Thank you to @arthurafarias for providing the optimized solution to MinAvgTwoSlice

codility's People

Contributors

arthurafarias avatar markhary avatar rogerfw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.