Kotlin coding challenges
Each challenge opens in Kotlin with a starter file ready. Run checks your code on the examples; Submit checks it against every test.
Basics
Short programs that read input and print an answer: a good place to start with Kotlin.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 1.Say helloRead a name and greet that person. | BasicsStrings | Easy | 100% | ||
| 2.Sum of two numbersRead two whole numbers and print their sum. | BasicsMath | Easy | 100% | ||
| 3.Even or oddSay whether a whole number is even or odd. | BasicsMath | Easy | 100% | ||
| 4.Largest of threePrint the largest of three numbers. | Basics | Easy | 100% | ||
| 5.Leap yearDecide whether a year is a leap year. | BasicsMath | Easy | 100% | ||
| 6.Celsius to FahrenheitConvert a temperature from Celsius to Fahrenheit. | BasicsMath | Easy | – | ||
| 7.Grade from scoreTurn a test score into a letter grade. | Basics | Easy | – | ||
| 8.FizzBuzzCount to n, saying Fizz, Buzz or FizzBuzz for multiples of 3 and 5. | BasicsMath | Easy | – | ||
| 9.Multiplication tablePrint the times table of a number from 1 to 10. | Basics | Easy | – | ||
| 10.Right triangleDraw a triangle of stars, one more on each line. | Basics | Easy | – | ||
| 11.Sum of a listRead a list of numbers and print their total. | BasicsArrays | Easy | – | ||
| 12.Count the vowelsCount how many vowels a line of text has. | BasicsStrings | Easy | – | ||
| 13.Reverse a linePrint a line of text backwards. | BasicsStrings | Easy | – | ||
| 14.Count the wordsCount the words in a line of text. | BasicsStrings | Easy | – |
Problems
Classic problems: write the function, and the tests call it.
| Status | Challenge | Topics | Level | Accepted | Save |
|---|---|---|---|---|---|
| 1.Two SumFind the two positions whose numbers add up to a target. | ArraysHash maps | Easy | – | ||
| 2.Valid PalindromeCheck whether text reads the same both ways, ignoring case and punctuation. | StringsTwo pointers | Easy | – | ||
| 3.Palindrome NumberCheck whether a number's digits read the same both ways. | Math | Easy | – | ||
| 4.Valid ParenthesesCheck that every bracket is closed by the right kind, in the right order. | StringsStacks | Easy | – | ||
| 5.Merge Sorted ArraysMerge two sorted arrays into one sorted array. | ArraysTwo pointersSorting | Easy | – | ||
| 6.Best Time to TradePick one day to buy and a later day to sell for the biggest profit. | ArraysGreedy | Easy | – | ||
| 7.Contains DuplicateCheck whether any number appears twice. | ArraysHash maps | Easy | – | ||
| 8.Valid AnagramCheck whether one word is a rearrangement of another. | StringsHash mapsSorting | Easy | – | ||
| 9.Missing NumberFind the one number missing from 0 to n. | ArraysMathBit manipulation | Easy | – | ||
| 10.Single NumberEvery number appears twice except one; find it. | ArraysBit manipulationHash maps | Easy | – | ||
| 11.Move ZerosMove every zero to the end, keeping the other numbers in order. | ArraysTwo pointers | Easy | – | ||
| 12.Binary SearchFind a number's position in a sorted array in log time. | ArraysBinary search | Easy | – | ||
| 13.Climbing StairsCount the ways to climb n stairs taking one or two at a time. | Dynamic programmingMathRecursion | Easy | – | ||
| 14.Majority ElementFind the value that fills more than half of the array. | ArraysHash maps | Easy | – | ||
| 15.Roman to IntegerTurn a Roman numeral into a number. | StringsMathHash maps | Easy | – | ||
| 16.Longest Common PrefixFind the longest start that every word shares. | Strings | Easy | – | ||
| 17.Count Set BitsCount the 1s in a number's binary form. | Bit manipulationMath | Easy | – | ||
| 18.Plus OneAdd one to a number stored as an array of digits. | ArraysMath | Easy | – | ||
| 19.First Unique CharacterFind the first letter that appears only once. | StringsHash maps | Easy | – | ||
| 20.Squares of a Sorted ArraySquare every number of a sorted array and keep it sorted. | ArraysTwo pointersSorting | Easy | – | ||
| 21.Longest Substring Without RepeatsFind the longest stretch of text with no repeated character. | StringsSliding windowHash maps | Medium | – | ||
| 22.Product Except SelfFor each position, multiply every other number, without dividing. | Arrays | Medium | – | ||
| 23.Maximum SubarrayFind the largest sum of a run of consecutive numbers. | ArraysDynamic programmingGreedy | Medium | – | ||
| 24.Top K FrequentReturn the k values that appear most often. | ArraysHash mapsSorting | Medium | – | ||
| 25.Three SumFind every distinct triple of numbers that adds up to zero. | ArraysTwo pointersSorting | Medium | – | ||
| 26.Container With Most WaterPick two walls that hold the most water between them. | ArraysTwo pointersGreedy | Medium | – | ||
| 27.Rotate MatrixTurn a square grid of numbers 90 degrees clockwise. | MatricesArrays | Medium | – | ||
| 28.Spiral MatrixRead a grid in a clockwise spiral from the outside in. | MatricesArrays | Medium | – | ||
| 29.Number of IslandsCount the separate islands of land on a grid map. | GraphsMatrices | Medium | – | ||
| 30.Coin ChangeMake an amount with as few coins as possible. | Dynamic programming | Medium | – | ||
| 31.Longest Increasing SubsequenceFind the longest strictly rising sequence you can pick out of an array. | Dynamic programmingBinary search | Medium | – | ||
| 32.Search in a Rotated ArrayBinary-search a sorted array that has been rotated. | ArraysBinary search | Medium | – | ||
| 33.Merge IntervalsMerge every pair of overlapping intervals. | ArraysSorting | Medium | – | ||
| 34.Days Until WarmerFor each day, count the days until a warmer one. | ArraysStacks | Medium | – | ||
| 35.House RobberTake the most from a row of houses without taking two neighbours. | Dynamic programming | Medium | – | ||
| 36.Jump GameDecide whether you can jump from the first square to the last. | ArraysGreedyDynamic programming | Medium | – | ||
| 37.Unique PathsCount the paths across a grid moving only right or down. | Dynamic programmingMathMatrices | Medium | – | ||
| 38.Subarray Sum Equals KCount the runs of consecutive numbers that add up to k. | ArraysHash maps | Medium | – | ||
| 39.Generate ParenthesesList every balanced string of n pairs of parentheses. | RecursionStrings | Medium | – | ||
| 40.Evaluate Reverse Polish NotationWork out an arithmetic expression written in postfix order. | StacksMath | Medium | 100% | ||
| 41.Trapping Rain WaterWork out how much rain water a skyline of bars holds. | ArraysTwo pointersStacks | Hard | – | ||
| 42.Median of Two Sorted ArraysFind the median of two sorted arrays taken together. | ArraysBinary search | Hard | – | ||
| 43.Edit DistanceCount the fewest single-letter edits that turn one word into another. | StringsDynamic programming | Hard | – | ||
| 44.Longest Valid ParenthesesFind the longest balanced run in a string of parentheses. | StringsStacksDynamic programming | Hard | – | ||
| 45.Largest Rectangle in a HistogramFind the biggest rectangle that fits under a bar chart. | ArraysStacks | Hard | – | ||
| 46.Sliding Window MaximumReport the largest number in every window of k as it slides along. | ArraysSliding window | Hard | – | ||
| 47.Minimum Window SubstringFind the shortest stretch of text that contains every letter of another string. | StringsSliding windowHash maps | Hard | – | ||
| 48.N QueensCount the ways to place n queens on an n × n board with none attacking another. | Recursion | Hard | – | ||
| 49.Word LadderFind the shortest chain of one-letter changes from one word to another. | GraphsStringsHash maps | Hard | – | ||
| 50.Pattern MatchingMatch text against a pattern with . and * wildcards. | StringsDynamic programmingRecursion | Hard | – | ||
| 51.Reverse a Linked ListTurn a linked list around so its last node comes first. | Linked lists | Easy | – | ||
| 52.Merge Two Sorted ListsJoin two sorted linked lists into one sorted list. | Linked listsTwo pointers | Easy | – | ||
| 53.Middle of a Linked ListFind the middle node of a linked list in one pass. | Linked listsTwo pointers | Easy | – | ||
| 54.Depth of a TreeCount the levels of a binary tree, from the root to its deepest leaf. | TreesRecursion | Easy | – | ||
| 55.Invert a TreeMirror a binary tree, swapping every node's left and right children. | TreesRecursion | Easy | – | ||
| 56.Remove the Nth Node From the EndUnlink the node n places from the end of a linked list. | Linked listsTwo pointers | Medium | – | ||
| 57.Add Two Numbers in ListsAdd two numbers stored digit by digit in linked lists. | Linked listsMath | Medium | – | ||
| 58.Tree Level by LevelList a binary tree's values one level at a time, left to right. | TreesGraphs | Medium | – | ||
| 59.Valid Search TreeCheck whether a binary tree keeps the search tree order everywhere. | TreesRecursion | Medium | – | ||
| 60.Reverse in Groups of kReverse a linked list k nodes at a time, leaving a short last group as it is. | Linked lists | Hard | – | ||
| 61.Best Path Sum in a TreeFind the path through a binary tree whose values add up to the most. | TreesRecursionDynamic programming | Hard | – |