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.
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.
This repository contains Android Studio project. We can quickly open the project simply by checking out this the project from git repository.
- Install Android Studio (we need version 3.3+ because of a bug that reruns tests incorrectly)
- Install git
brew install git
using cmd - Import project by using Android Studio menu:
File -> New -> Project From Version Control -> Git
- Enter Repository URL
https://github.com/igorwojda/kotlin-coding-puzzle.git
and clickclone
- Navigate to app/src/test/java/com/igorwojda folder in
Project
view or app/java/com (test)/igorwojda inAndroid
view in project panel. - Optionally install Markdown Navigator plugin for Android studio to have ice preview of markdown files (files containing puzzles description)
Each puzzle is located in separate package and it contains 3 files (screen):
Puzzle.md
- description of the puzzlePuzzle.kt
- contains empty method/class where puzzle should be solved and set of tests to runPuzzleSolution.kt
- file that contains one or more puzzle solutions (encapsulated in Kotlinobject
just to avoid conflicts with other coding puzzles)
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.
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:
- First, we have to understand the problem
- After understanding make a plan
- Carry out the plan. Look back
- Look back on your work. How could it be better?
We can translate this method into more concrete steps.
Understand the problem
- Can I rephrase problem using your my own words?
- What are the inputs?
- What are the outputs?
- How should I label the important pieces of data that are a part of the problem?
- Explore concrete examples
- Start with simple examples and progress to more complex ones
- Explore empty inputs
- Explore invalid inputs
Break it down
- 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
- Try to refactor te code
- Improve performance (Big-O notation)
- Check how other people solved this problem
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
- Sentence capitalization
- Range contains range?
- Add up to
- Count up and down
- Get all pairs
- List count unique values
Apprentice
- Palindrome
- Tolerant palindrome
- Anagram
- Max occurring char
- String reversal
- Find the vowels
- Int reversal
Warrior
- Int queue
- Generic queue
- Combine two queues
- Two stack queue
- Int stack
- Generic stack
- Bubble sort
- Selection sort
- Square equals
- Sum zero
- Max sub-list list sum
- Digit frequency
- Get duplicated arguments
Commander
- List chunking
- Linked list
- Linked list midpoint
- Circular linked list?
- Linked list take n-th element from last
- Tree traversal
- Tree level width
- Binary Search Tree (insert)
- Binary Search Tree (validate)
- Merge sort
- Pyramid generator
- Steps generator
- Fibonacci
- Fibonacci add recursive cache
- Fizz Buzz
- Spiral matrix generator
- Factorial
- Print number
- Print number with steps
- Cracking the Coding Interview
- Algorithms, 4th Edition
- Master the Coding Interview Data Structures + Algorithms
- JavaScript Algorithms and Data Structures Masterclass
- The Coding Interview Bootcamp Algorithms + Data Structures
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.