All challenges

Scala coding challenges

Each challenge opens in Scala 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 Scala.

StatusChallengeLevelSave
1.Say helloRead a name and greet that person.Easy
2.Sum of two numbersRead two whole numbers and print their sum.Easy
3.Even or oddSay whether a whole number is even or odd.Easy
4.Largest of threePrint the largest of three numbers.Easy
5.Leap yearDecide whether a year is a leap year.Easy
6.Celsius to FahrenheitConvert a temperature from Celsius to Fahrenheit.Easy
7.Grade from scoreTurn a test score into a letter grade.Easy
8.FizzBuzzCount to n, saying Fizz, Buzz or FizzBuzz for multiples of 3 and 5.Easy
9.Multiplication tablePrint the times table of a number from 1 to 10.Easy
10.Right triangleDraw a triangle of stars, one more on each line.Easy
11.Sum of a listRead a list of numbers and print their total.Easy
12.Count the vowelsCount how many vowels a line of text has.Easy
13.Reverse a linePrint a line of text backwards.Easy
14.Count the wordsCount the words in a line of text.Easy

Problems

Classic problems: write the function, and the tests call it.

StatusChallengeLevelSave
1.Two SumFind the two positions whose numbers add up to a target.Easy
2.Valid PalindromeCheck whether text reads the same both ways, ignoring case and punctuation.Easy
3.Palindrome NumberCheck whether a number's digits read the same both ways.Easy
4.Valid ParenthesesCheck that every bracket is closed by the right kind, in the right order.Easy
5.Merge Sorted ArraysMerge two sorted arrays into one sorted array.Easy
6.Best Time to TradePick one day to buy and a later day to sell for the biggest profit.Easy
7.Contains DuplicateCheck whether any number appears twice.Easy
8.Valid AnagramCheck whether one word is a rearrangement of another.Easy
9.Missing NumberFind the one number missing from 0 to n.Easy
10.Single NumberEvery number appears twice except one; find it.Easy
11.Move ZerosMove every zero to the end, keeping the other numbers in order.Easy
12.Binary SearchFind a number's position in a sorted array in log time.Easy
13.Climbing StairsCount the ways to climb n stairs taking one or two at a time.Easy
14.Majority ElementFind the value that fills more than half of the array.Easy
15.Roman to IntegerTurn a Roman numeral into a number.Easy
16.Longest Common PrefixFind the longest start that every word shares.Easy
17.Count Set BitsCount the 1s in a number's binary form.Easy
18.Plus OneAdd one to a number stored as an array of digits.Easy
19.First Unique CharacterFind the first letter that appears only once.Easy
20.Squares of a Sorted ArraySquare every number of a sorted array and keep it sorted.Easy
21.Longest Substring Without RepeatsFind the longest stretch of text with no repeated character.Medium
22.Product Except SelfFor each position, multiply every other number, without dividing.Medium
23.Maximum SubarrayFind the largest sum of a run of consecutive numbers.Medium
24.Top K FrequentReturn the k values that appear most often.Medium
25.Three SumFind every distinct triple of numbers that adds up to zero.Medium
26.Container With Most WaterPick two walls that hold the most water between them.Medium
27.Rotate MatrixTurn a square grid of numbers 90 degrees clockwise.Medium
28.Spiral MatrixRead a grid in a clockwise spiral from the outside in.Medium
29.Number of IslandsCount the separate islands of land on a grid map.Medium
30.Coin ChangeMake an amount with as few coins as possible.Medium
31.Longest Increasing SubsequenceFind the longest strictly rising sequence you can pick out of an array.Medium
32.Search in a Rotated ArrayBinary-search a sorted array that has been rotated.Medium
33.Merge IntervalsMerge every pair of overlapping intervals.Medium
34.Days Until WarmerFor each day, count the days until a warmer one.Medium
35.House RobberTake the most from a row of houses without taking two neighbours.Medium
36.Jump GameDecide whether you can jump from the first square to the last.Medium
37.Unique PathsCount the paths across a grid moving only right or down.Medium
38.Subarray Sum Equals KCount the runs of consecutive numbers that add up to k.Medium
39.Generate ParenthesesList every balanced string of n pairs of parentheses.Medium
40.Evaluate Reverse Polish NotationWork out an arithmetic expression written in postfix order.Medium
41.Trapping Rain WaterWork out how much rain water a skyline of bars holds.Hard
42.Median of Two Sorted ArraysFind the median of two sorted arrays taken together.Hard
43.Edit DistanceCount the fewest single-letter edits that turn one word into another.Hard
44.Longest Valid ParenthesesFind the longest balanced run in a string of parentheses.Hard
45.Largest Rectangle in a HistogramFind the biggest rectangle that fits under a bar chart.Hard
46.Sliding Window MaximumReport the largest number in every window of k as it slides along.Hard
47.Minimum Window SubstringFind the shortest stretch of text that contains every letter of another string.Hard
48.N QueensCount the ways to place n queens on an n × n board with none attacking another.Hard
49.Word LadderFind the shortest chain of one-letter changes from one word to another.Hard
50.Pattern MatchingMatch text against a pattern with . and * wildcards.Hard
51.Reverse a Linked ListTurn a linked list around so its last node comes first.Easy
52.Merge Two Sorted ListsJoin two sorted linked lists into one sorted list.Easy
53.Middle of a Linked ListFind the middle node of a linked list in one pass.Easy
54.Depth of a TreeCount the levels of a binary tree, from the root to its deepest leaf.Easy
55.Invert a TreeMirror a binary tree, swapping every node's left and right children.Easy
56.Remove the Nth Node From the EndUnlink the node n places from the end of a linked list.Medium
57.Add Two Numbers in ListsAdd two numbers stored digit by digit in linked lists.Medium
58.Tree Level by LevelList a binary tree's values one level at a time, left to right.Medium
59.Valid Search TreeCheck whether a binary tree keeps the search tree order everywhere.Medium
60.Reverse in Groups of kReverse a linked list k nodes at a time, leaving a short last group as it is.Hard
61.Best Path Sum in a TreeFind the path through a binary tree whose values add up to the most.Hard