Scotiabank Scala Interview Questions
(c) Scotiabank 2017
A selection of interview problems for developer candidates.
There are 2 exercises to complete.
- Exercise #1 is a data structure question in src/main/scala/test/queue.scala
- Exercise #2 is a question on automatic typeclass derivation using shapeless in src/main/scala/test/eq.scala
You should complete both questions.
Implementation considerations
- Exercise #1 Immutable FIFO Queue borrows from the default scala immutable Queue implementation described here
- Exercise #2 Type Class Derivation with shapeless borrows from Miles Sabin (shapeless creator) on here
- Both solutions are thoroughly tested:
- scoverage report result is:
[info] Statement coverage.: 100.00% [info] Branch coverage....: 100.00% [info] Coverage reports completed [info] 100% Coverage !
- FifoQueue is tested here, with the test output:
[info] FifoQueueTest: [info] Time complexity tests [info] - isEmpty should have Q(1) in milliseconds [info] - insert should have Q(1) in milliseconds [info] - remove should have amortized Q(1) = less than 2 milliseconds [info] - insert should not be constant in nanoseconds [info] Functional tests [info] isEmpty should [info] - return true for empty Queue [info] - return false for non empty Queue [info] insert should [info] - return a new queue with the element prepended [info] - not mutate the original queue [info] remove should [info] - return a new queue with the first inserted element removed [info] - return removed element [info] - not mutate the original queue [info] toString should [info] - return all values for a non empty queue [info] - return empty string for an empty queue
- Type class derivation is tested here, with the test output:
[info] EqTest: [info] Equivalence test [info] product should [info] - be equal to itself [info] - be equal to another instance with same type and values [info] - be different by values [info] coproduct should [info] - be equal to itself [info] - be equal to another instance with same type and values [info] - be different by values [info] custom type should [info] - be equal to itself [info] - be equal to another instance with same type and values [info] - be different by values [info] - be different by types
- scoverage report result is:
- Code is auto formatted using scalariform;
- Coding style is enforced with scalastyle and wartremover;