Swift coding questions
Write Swift in the browser and run real tests.
Algorithms and Swift language problems like the ones in iOS coding rounds. Click Run to test your code, then Submit to check it against every test.
Write Swift and run real tests in the browser.
Find the two numbers in an array that add up to a target, in one pass.
Easy15 mins7 testsAlgorithmsData structuresCheck that every bracket in a string is closed by the same type, in the right order.
Easy15 mins9 testsAlgorithmsData structuresFind the biggest profit from one buy and one later sell, in a single pass.
Easy15 mins9 testsAlgorithmsUse binary search to find the first broken CI build with as few checks as possible.
Easy15 mins8 testsAlgorithmsReverse a singly linked list in place by turning every next pointer around.
Easy15 mins8 testsAlgorithmsData structuresMerge overlapping calendar events into busy blocks by sorting first, then scanning once.
Medium20 mins9 testsAlgorithmsGroup words made of the same letters by using a dictionary with a smart key.
Medium20 mins9 testsAlgorithmsData structuresCount how often each hashtag is used and return the k most popular ones.
Medium20 mins9 testsAlgorithmsData structuresFor each index, multiply every other number, without division, using prefix and suffix products.
Medium20 mins8 testsAlgorithmsFind the longest run of unique characters with a sliding window and a dictionary.
Medium20 mins10 testsAlgorithmsData structuresFind the closest view that contains two given views, using superview pointers.
Medium20 mins9 testsAlgorithmsData structuresUIKitWalk a view tree level by level with breadth-first search and return the names of each level.
Medium20 mins8 testsAlgorithmsData structuresUIKitBuild a prefix tree that returns sorted search suggestions without scanning every word.
Medium25 mins10 testsAlgorithmsData structuresCount connected regions of filled pixels in a mask with flood fill (the "number of islands" problem).
Medium20 mins9 testsAlgorithmsRotate an n x n pixel grid 90 degrees clockwise in place, with a transpose and a mirror.
Medium20 mins8 testsAlgorithmsBuild a generic binary heap with push, pop and peek in O(log n), ordered by any comparator.
Medium30 mins10 testsData structuresGenericsFind a build order for Swift modules from their dependencies with a topological sort, and detect cycles.
Hard35 mins11 testsAlgorithmsData structuresToolingBuild a generic cache that drops the least recently used item when it is full. Every operation must be O(1).
Medium30 mins10 testsData structuresGenericsRun an action only after the calls stop for a short time, like a search box that waits until the user stops typing.
Medium25 mins9 testsConcurrencySwiftRun an action at most once per time window. The first call runs right away, and the last call in the window runs when the window ends.
Medium25 mins9 testsConcurrencySwiftRetry a failing async operation, and double the wait time after each failure.
Medium20 mins8 testsConcurrencyNetworkingTransform an array with async work in parallel, keep the input order, and never run more than N tasks at once.
Hard35 mins8 testsConcurrencyGenericsBuild a bank account as an actor so many tasks can deposit, withdraw and transfer at the same time without data races.
Easy15 mins10 testsConcurrencySwiftDecode a real-looking API response with snake_case keys, ISO 8601 dates, nested and optional fields, and an enum that survives new values.
Medium25 mins11 testsSwiftNetworkingWrite a @Clamped property wrapper that keeps a value inside a range, like a volume from 0 to 100.
Easy15 mins9 testsSwiftGenericsBuild a typed publish/subscribe bus where a subscription ends by itself when its token is released.
Medium25 mins10 testsMemory & ARCArchitectureGenericsParse custom-scheme deep links and universal links into a type-safe Route enum with URLComponents.
Medium25 mins12 testsArchitectureSwiftParse version strings like "2.0.0-beta.1" and sort them correctly with Comparable, following the semver rules.
Medium25 mins11 testsSwiftProtocolsTurn a date into "just now", "5m ago", "2h ago", "yesterday", "3d ago" or a short date, with the current time injected for testing.
Easy15 mins10 testsSwiftTestingBuild a small DI container that registers factories by type, supports singleton and transient scopes, and throws for missing types.
Medium25 mins11 testsArchitectureGenericsWrite a generic memoize function that caches results, plus a version that also works for recursive functions like Fibonacci.
Easy15 mins10 testsSwiftGenericsPerformanceBuild an NSCache-like cache with a total cost limit that evicts the least recently used items until it fits.
Medium30 mins10 testsData structuresMemory & ARCPerformanceBuild an actor that loads pages for an infinite list, ignores duplicate loads while one is running, and stops at the last page.
Hard35 mins9 testsConcurrencyArchitectureNetworking