iosNudge

Swift coding questions

Write Swift in the browser and run real tests.

Written for interviews Swift that runs in the browser Simple English with examples

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.

33 questions 12h 10m total
  • Find the two numbers in an array that add up to a target, in one pass.

    Easy15 mins7 tests
  • Check that every bracket in a string is closed by the same type, in the right order.

    Easy15 mins9 tests
  • Find the biggest profit from one buy and one later sell, in a single pass.

    Easy15 mins9 tests
  • Use binary search to find the first broken CI build with as few checks as possible.

    Easy15 mins8 tests
  • Reverse a singly linked list in place by turning every next pointer around.

    Easy15 mins8 tests
  • Merge overlapping calendar events into busy blocks by sorting first, then scanning once.

    Medium20 mins9 tests
  • Group words made of the same letters by using a dictionary with a smart key.

    Medium20 mins9 tests
  • Count how often each hashtag is used and return the k most popular ones.

    Medium20 mins9 tests
  • For each index, multiply every other number, without division, using prefix and suffix products.

    Medium20 mins8 tests
  • Find the longest run of unique characters with a sliding window and a dictionary.

    Medium20 mins10 tests
  • Find the closest view that contains two given views, using superview pointers.

    Medium20 mins9 tests
  • Walk a view tree level by level with breadth-first search and return the names of each level.

    Medium20 mins8 tests
  • Build a prefix tree that returns sorted search suggestions without scanning every word.

    Medium25 mins10 tests
  • Count connected regions of filled pixels in a mask with flood fill (the "number of islands" problem).

    Medium20 mins9 tests
  • Rotate an n x n pixel grid 90 degrees clockwise in place, with a transpose and a mirror.

    Medium20 mins8 tests
  • Build a generic binary heap with push, pop and peek in O(log n), ordered by any comparator.

    Medium30 mins10 tests
  • Find a build order for Swift modules from their dependencies with a topological sort, and detect cycles.

    Hard35 mins11 tests
  • Build a generic cache that drops the least recently used item when it is full. Every operation must be O(1).

    Medium30 mins10 tests
  • Run an action only after the calls stop for a short time, like a search box that waits until the user stops typing.

    Medium25 mins9 tests
  • Run 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 tests
  • Retry a failing async operation, and double the wait time after each failure.

    Medium20 mins8 tests
  • Transform an array with async work in parallel, keep the input order, and never run more than N tasks at once.

    Hard35 mins8 tests
  • Build a bank account as an actor so many tasks can deposit, withdraw and transfer at the same time without data races.

    Easy15 mins10 tests
  • Decode 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 tests
  • Write a @Clamped property wrapper that keeps a value inside a range, like a volume from 0 to 100.

    Easy15 mins9 tests
  • Build a typed publish/subscribe bus where a subscription ends by itself when its token is released.

    Medium25 mins10 tests
  • Parse custom-scheme deep links and universal links into a type-safe Route enum with URLComponents.

    Medium25 mins12 tests
  • Parse version strings like "2.0.0-beta.1" and sort them correctly with Comparable, following the semver rules.

    Medium25 mins11 tests
  • Turn 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 tests
  • Build a small DI container that registers factories by type, supports singleton and transient scopes, and throws for missing types.

    Medium25 mins11 tests
  • Write a generic memoize function that caches results, plus a version that also works for recursive functions like Fibonacci.

    Easy15 mins10 tests
  • Build an NSCache-like cache with a total cost limit that evicts the least recently used items until it fits.

    Medium30 mins10 tests
  • Build an actor that loads pages for an infinite list, ignores duplicate loads while one is running, and stops at the last page.

    Hard35 mins9 tests