Swift coding challenges

225 challenges you can solve in Swift, from first loops to graphs, dynamic programming and machine learning. Write your code in the browser, run the tests instantly and get an AI review.

Easy · 134 Medium · 67 Hard · 24

Skills you'll practise: CountingDigit extractionString splitting2D listsArithmeticFormulasListsLoopsConditionsDivisibilityFloating pointGradient descent
  • Python · C++ · C#
  • Automated tests
  • AI code review
  • Community solutions
226
Challenges
123
Solutions shared
9
Languages

All challenges

Search by topic, language, or difficulty.

225 challenges
Easy

Fibonacci Number

Return the n-th Fibonacci number.

You'll learn IterationUpdating two variables
BeginnerLoopsSequencesStudent-beginner
Easy

Average of Three

Average three whole numbers.

You'll learn ArithmeticDivision
BeginnerLearning-pathVariables
Easy

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

You'll learn ArithmeticReturn values
BeginnerLearning-pathVariables
Hard

Minimum Network Connection Cost

Choose undirected links so that every vertex can reach every other vertex, with minimum total cost.

You'll learn Kruskal's algorithmUnion-find
Disjoint-setsGraphsMinimum-spanning-tree
No solutions yet
Easy

Pyramid Rows

Draw a right-aligned pyramid of # blocks.

You'll learn String patternsPadding
BeginnerLearning-pathNested-loopsPatterns
Medium

Island Perimeter

Measure the coastline of land cells in a grid.

You'll learn Edge counting4-neighbor checks
AdvancedGridsHackathon
No solutions yet
Medium

Shortest Weighted Routes

Find the minimum total route cost from city 1 to each city.

You'll learn Dijkstra's algorithmLazy deletion
GraphsPriority-queuesShortest-path
No solutions yet
Medium

Tic-Tac-Toe Winner

Decide the result of a tic-tac-toe board.

You'll learn Win conditionsDiagonals
BeginnerConditionsGridsLearning-path
Hard

Trapping Rain Water

Compute how much rain water an elevation map holds.

You'll learn Two pointersPrefix maxima
AdvancedArraysCompetitive-programmingGreedy
Easy

Hollow Square

Draw the outline of a square with * characters.

You'll learn Edge detectionBuilding strings
BeginnerLearning-pathNested-loopsPatterns
Hard

Mini Stack-Language Interpreter

Evaluate a small stack language.

You'll learn TokenizingExecuting instructions
InterpretersParsingStacks
No solutions yet
Medium

Recursive Palindrome

Check a palindrome recursively, ignoring case and punctuation.

You'll learn Base casesString cleaning
BeginnerLearning-pathRecursionStrings
Hard

Count Inversions

Count the out-of-order pairs in a list.

You'll learn Merge sortDivide and conquer
AdvancedCompetitive-programmingSorting
No solutions yet
Easy

Min and Max Together

Find the smallest and largest value in one pass.

You'll learn Single passMultiple return values
ArraysBeginnerFunctionsLearning-path
Hard

Sliding Window Maximum

Report the maximum of every window of k numbers.

You'll learn Monotonic dequeO(n) windows
AdvancedCompetitive-programmingSliding-window
No solutions yet
Easy

Cash: Fewest Coins

Give change with as few U.S. coins as possible.

You'll learn Greedy algorithmsCoin change
BeginnerGreedyStudent-beginnermath
Easy

Halve Until One

Count how many halvings bring a number down to 1.

You'll learn While loopsCounting
BeginnerLearning-pathLoops
Medium

A* Search on a Weighted Grid

Find the cheapest path across a grid of terrain costs with A*, the search algorithm behind game and robot pathfinding.

You'll learn A* searchHeuristics
GraphsGridsShortest-pathai