My playground project for solving algorithm contest / interview problems
Contains a type-checked Runner that can read multiple test cases from file and verify the solution logic results against the expected results (also read from file)
When working on a new problem the section in the runner must be modified to the correct inputs / outputs
For adding or viewing extra formats use: DataParser
Sample:
type Input = (Int, Vector[Int])
type Output = Vector[Int]
private val inputDatasetParser = SingleNumber_ArrayOfInt
private val outputDatasetParser = ArrayOfInt
private val solution: Input => Output = ((k: Int, v: Vector[Int]) => CyclicRotation.solution(v.toArray, k)).tupled.andThen(_.toVector)
or
type Input = (Int, Int, Int)
type Output = Int
private val inputDatasetParser = IntTuple3
private val outputDatasetParser = SingleNumber
private val solution: Input => Output = (FrogJmp.solution _).tupled
implicit val showTupleInt3 = DebugUtil.tuple3Show[Int, Int, Int]
Sample run output :
[INFO] Found: [3] tests
[INFO] Running #1 ..
[INPUT] Vector(3, 2, 6, -1, 4, 5, -1, 2)
[RESULT] 17
[TIME] 10.3946 ms
[INFO] SUCCESS
[INFO] Running #2 ..
[INPUT] Vector(5, 5, 5)
[RESULT] 0
[TIME] 0.1455 ms
[INFO] SUCCESS
[INFO] Running #3 ..
[INPUT] Vector(1, 1, 1)
[RESULT] 0
[TIME] 0.1152 ms
[INFO] SUCCESS
[INFO] ALL tests SUCCESS
While working on a solution a useful utility to use (customize) is the test case Generator
There is a strong bias towards solutions to algorithm problems using imperative programming.
My goal is to use as many algorithm problems using pure functions and functional programming
Here are some of my 100% solutions. Only codility so far, but planning to do more.
- Iterations
- Arrays
- Time complexity
- Counting Elements
- Prefix Sums
- PassingCars
- GenomicRangeQuery
- MinAvgTwoSlice
- CountDiv
- Sorting
- MaxProductOfThree
- Distinct
- Triangle
- NumberOfDiscIntersections
- Stacks and Queues
- Leader
- Dominator
- EquiLeader
- Maximum slice problem
- MaxProfit
- MaxSliceSum
- MaxDoubleSliceSum