Skip to content

omokolataiwo/kotlin-coding-puzzle

 
 

Repository files navigation

Kotlin coding puzzles

This repository contains a set of programming puzzles that meant to be solved using Kotlin language (no worries hints, solutions and tests that will verify your solution are here as well). Purpose of this repository is to help you to practice deliberately and develop strong problem solving skills. This will make you better programmer and will help you to get new job by passing whiteboard coding interviews.

Solutions

Repository contains one or more solutions for any given puzzle, however keep in mind that each puzzle will usually have more than one solution. Even simple puzzle like String reversal can be solved in 10 different ways. Usually we are compare various solutions using (Big O notation) to determine space/time complexity and latter we look at code readability.

How do I start?

Opening this project

This repository contains Android Studio project. We can quickly open the project simply by checking out this the project from git repository.

  1. Install Android Studio (we need version 3.3+ because of a bug that reruns tests incorrectly)
  2. Install git brew install git using cmd
  3. Import project by using Android Studio menu: File -> New -> Project From Version Control -> Git
  4. Enter Repository URL https://github.com/igorwojda/kotlin-coding-puzzle.git and click clone
  5. Navigate to app/src/test/java/com/igorwojda folder in Project view or app/java/com (test)/igorwojda in Android view in project panel.
  6. Optionally install Markdown Navigator plugin for Android studio to have ice preview of markdown files (files containing puzzles description)

Puzzle structure

Each puzzle is located in separate package and it contains 3 files (screen):

  • Puzzle.md - description of the puzzle
  • Puzzle.kt - contains empty method/class where puzzle should be solved and set of tests to run
  • PuzzleSolution.kt - file that contains one or more puzzle solutions (encapsulated in Kotlin object just to avoid conflicts with other coding puzzles)

Running tests

Open Puzzle.kt file for a any puzzle. Locate class with Test suffix (PuzzleTest). Click on the green green arrow close to line number to run one or more tests in the class (screen). After running the test you can rerun last configuration using Run command (⌘ + R).

Larger puzzles will have larger test base, so tests have to be uncommented one by one while solving various steps of the given puzzle.

Solving puzzles

To be good at solving programming puzzles you will also need a proper problem solving strategy.

In 1945 Hungarian mathematician George Pólya, described famous method of problem solving:

We can translate this method into more concrete steps.

Understand the problem

  1. Can I rephrase problem using your my own words?
  2. What are the inputs?
  3. What are the outputs?
  4. How should I label the important pieces of data that are a part of the problem?
  5. Explore concrete examples
    1. Start with simple examples and progress to more complex ones
    2. Explore empty inputs
    3. Explore invalid inputs

Break it down

  1. Write exact, atomic steps we need to take (as comments in file)

Solve it

Solve the problem. If you can't just solve similar problem or try to solve current problem by temporally excluding most difficult part.

Refactor & Simplify

  1. Try to refactor te code
  2. Improve performance (Big-O notation)
  3. Check how other people solved this problem

Kotlin programing puzzles

Puzzles are segregated by different difficulty. Some puzzle may contain a reference to puzzles that should be solved before to have better understanding of the problem. To succeed you need to practice often, repeat same puzzles multiple times and be persistent over time. Take your time before you take a look at the presented solution. Good luck!

New in Town

Apprentice

Warrior

Commander

References

Books

Video courses

Articles

Coding problems websites

Contribute

If you think something is incorrect, you have found a new puzzle, have a better solution or simply you want to add new puzzle please create PR or open a new issue.

Follow me

avatar.png

Twitter | Medium | Linkedin

About

Kotlin coding puzzle and solutions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%