CS fundamentals and algorithms interview questions
48 questions from real iOS interviews. Topics: Data structures, algorithms, OS, networking (in an iOS context).
- CS fundamentals and algorithmsShort answerAppleinterview report
Stacks and queues
What's the difference between a stack and a queue?
#stack #queue #data-structure #navigation
- CS fundamentals and algorithmsMultiple choiceSnapinterview report
Array vs linked list
You're picking a data structure for the message list on a chat screen. Which is the most accurate reason a Swift Array beats a linked list here?
#array #linked-list #complexity
- CS fundamentals and algorithmsMultiple choice
Swift collection complexity
Which of these Swift collection operations have O(1) average time complexity? Select all that apply.
#complexity #array #set #dictionary
- CS fundamentals and algorithmsShort answer카카오
TCP vs UDP
What's the difference between TCP and UDP? When a packet is lost, what happens under each one?
#tcp #udp #network #urlsession
- CS fundamentals and algorithmsMultiple choice
Image formats
Which statements about image formats are correct? Select all that apply.
#png #jpeg #heic #webp
- CS fundamentals and algorithmsMultiple choiceZomato
Interval overlap
You're writing a function that decides whether two text highlight ranges overlap. For two half-open ranges a = [a.lower, a.upper) and b = [b.lower, b.upper), w…
#range #interval #overlap #nsrange
- CS fundamentals and algorithmsShort answerZoom
Linked list intersection
Two singly linked lists may share their tail nodes. How do you find the first node they actually share (the same instance, not a node with an equal value) in O…
#linked-list #two-pointers #identity #algorithm
- CS fundamentals and algorithmsShort answerZalandointerview report
Balanced brackets
A Swift string mixes ()[]{} and you're checking with a stack whether they nest correctly. When you hit a closing bracket, what comparison do you make?
#stack #brackets #string #algorithm
- CS fundamentals and algorithmsShort answer
Array insert cost
A live feed calls posts.insert(newPost, at: 0) every time a new post arrives. What goes wrong once 50,000 posts have piled up?
#array #complexity #prepend #deque
- CS fundamentals and algorithmsShort answerMetainterview report
Hash maps and Dictionary
If you had to implement a hash map yourself, how would you build it?
#hashmap #dictionary #hashable #collision
- CS fundamentals and algorithmsMultiple choice
Hashable consistency
What problem does this type cause when you put it in a Set? …
#hashable #equatable #set #bug
- CS fundamentals and algorithmsMultiple choice
Bit operations and OptionSet
Given this code, which statements about OptionSet and bit operations are correct? Select all that apply. …
#bitwise #optionset #bitmask #enum
- CS fundamentals and algorithmsShort answer
Choosing a search algorithm
You're building name search over a list of 10,000 contacts. How do linear search and sort-then-binary-search compare, and what would you actually use in a ship…
#binary-search #linear-search #dictionary #trie
- CS fundamentals and algorithmsShort answer
Processes and threads
What's the difference between a process and a thread? What do threads share, and what does each one keep to itself?
#process #thread #os #extension
- CS fundamentals and algorithmsMultiple choice
Thread explosion
Running this code, which downloads 200 URLs with GCD, sends the system thread count past 60 and freezes the app. What's the most accurate cause? …
#thread-explosion #gcd #concurrent-queue #semaphore
- CS fundamentals and algorithmsShort answerSnapinterview report
Sorting and Swift sort
Can you compare merge sort and quicksort: how each works, and their time and space complexity?
#sort #stable-sort #merge-sort #quick-sort
- CS fundamentals and algorithmsMultiple choice
Stable sorting
You take a contacts array already sorted by name and re-sort it with contacts.sort { $0.isFavorite && !$1.isFavorite }, and the names inside the favorites grou…
#sort #stable-sort #ui
- CS fundamentals and algorithmsMultiple choice
Pure functions
Which of these are pure functions (same output for the same input, no side effects)? Select all that apply.
#pure-function #functional #side-effect #swiftui
- CS fundamentals and algorithmsShort answerApple
O(1) max stack
You want a stack, like an editor's undo stack, that returns the "current maximum" of the pushed values in O(1). First define the interface as a Swift protocol,…
#stack #max-stack #protocol #xctest
- CS fundamentals and algorithmsShort answerMeta
Streaming moving average
Frame times arrive as a stream, one per frame. Design a type that returns "the average of the last k frames" instantly whenever asked. It's called 60 times a s…
#ring-buffer #sliding-window #moving-average #fps
- CS fundamentals and algorithmsShort answerReddit
Anchored two-way lookup
Chat messages sit in an array sorted by id ascending. When the user taps a push notification to jump to a specific message, how would you write a function that…
#binary-search #sorted-array #pagination #anchor
- CS fundamentals and algorithmsMultiple choicePayPal
Sliding window preconditions
You solved "longest contiguous run of transaction amounts whose sum stays at or under a limit L" in O(n) with a two-pointer sliding window. The interviewer ask…
#sliding-window #two-pointers #prefix-sum #monotonic
- CS fundamentals and algorithmsShort answerAudible
Rearranging without adjacent duplicates
You have a list of posts for a feed and need to reorder them so that no two posts by the same author appear back to back. What algorithm do you use, and what's…
#greedy #heap #priority-queue #feed
- CS fundamentals and algorithmsShort answerMastercard
Parsing corrupted logs
Your app writes a network log file. Each line has the format userID(4 digits) pageName startTime(hh:mm:ss) endTime(hh:mm:ss), but some lines are corrupted. How…
#parsing #validation #log #top-k
- CS fundamentals and algorithmsMultiple choiceJPMorgan Chase
Time window anomaly detection
A list of transactions (card number, country, time) arrives sorted by time ascending. What's the most efficient way to detect "the same card used in two differ…
#hashmap #time-window #stream #fraud
- CS fundamentals and algorithmsMultiple choiceCapital Oneinterview report
Luhn checksum
On a card number entry screen you want to validate the number with the Luhn algorithm before sending it to the server. Which statements about Luhn validation a…
#luhn #checksum #validation #card-number
- CS fundamentals and algorithmsShort answerPinterestinterview report
Infinite scroll cursors
In an endless iOS list like a pin board, you want to stop the same item showing twice or the next page going missing. If you use a cursor instead of an offset,…
#pagination #cursor #infinite-scroll #deduplication
- CS fundamentals and algorithmsShort answerSquare
Inventory domain design
You're designing a Swift inventory system that processes receive, reserve, sell, and cancel operations in sequence. What domain type protects the invariants on…
#object-oriented-design #inventory #invariant #domain-model
- CS fundamentals and algorithmsShort answerBilibili
Base-36 string addition
You need to add two base-36 strings made of digits and letters without converting them to integers (so no overflow) and return the result as a string. How do y…
#string #base36 #carry #arithmetic
- CS fundamentals and algorithmsShort answerDeloitteinterview report
O(1) LRU cache
You're designing an LRU cache that keeps only recently used items. To make get and put average O(1), what does the HashMap do and what does the doubly linked l…
#lru-cache #hash-map #linked-list #data-structure
- CS fundamentals and algorithmsShort answer오늘의집
Shortest path with BFS
A home decor recommender follows a graph of room-to-room connections to find the minimum number of moves. When every edge costs the same, why does BFS guarante…
#graph #bfs #visited-set #shortest-path
- CS fundamentals and algorithmsShort answerN26interview report
HashMap vs Set
In a one-hour coding test you have to find duplicates in a list of customer IDs and also count how often each ID appears. When would you use Swift's Set and wh…
#hashmap #set #complexity #swift
- CS fundamentals and algorithmsShort answer
LRU cache
You need to write an in-memory image cache with LRU eviction yourself. Which data structures give you O(1) get and put?
#lru #cache #linked-list #dictionary
- CS fundamentals and algorithmsMultiple choice
Floating point and Decimal
In payment amount math, 0.1 + 0.2 == 0.3 came back false and a test failed. Which statements about floating point and Decimal are correct? Select all that appl…
#floating-point #decimal #ieee754 #currency
- CS fundamentals and algorithmsShort answer
QUIC and mobile networks
A user on the subway keeps bouncing between Wi-Fi and LTE, and your app's requests keep dropping. How do HTTP/2 over TCP and HTTP/3 over QUIC each handle that?
#quic #http3 #tcp #connection-migration
- CS fundamentals and algorithmsShort answer
First request latency
On a cold start, your app's first API response takes 800ms and every one after that takes 120ms. Can you walk me through what happens in the network stack in b…
#dns #tls #handshake #latency
- CS fundamentals and algorithmsShort answerMetainterview report
View hierarchy tree search
You're given a specific UIView instance in an original view hierarchy, plus a copy of that hierarchy with the same structure. How would you design a function t…
#bfs #dfs #tree #view-hierarchy
- CS fundamentals and algorithmsShort answerTikTok
Recursion and stack limits
You're recursively walking a nested JSON document thousands of levels deep, and it crashes only on a background thread. What's the cause?
#recursion #iteration #stack-overflow #thread-stack
- CS fundamentals and algorithmsMultiple choice
Cache locality
You iterate over 100,000 coordinates and sum distances. Between these two versions, what's the main reason A is noticeably faster than B? …
#cache-locality #struct #class #memory-layout
- CS fundamentals and algorithmsShort answerGoogle
K nearest places
You have tens of thousands of places with an id and coordinates (latitude, longitude). Given the user's current location, design a function that finds the 10 n…
#k-nearest #heap #quickselect #geo
- CS fundamentals and algorithmsShort answerPayPal
LRU cache with TTL
You've implemented an LRU cache and the interviewer follows up: "Now make each entry expire a fixed time after it's stored. What gets more expensive?" Explain …
#lru #ttl #cache #expiry
- CS fundamentals and algorithmsShort answerMicrosoft
Connected components, recursion limits
An image mask comes as an N×M grid where 1 is foreground and 0 is background. How would you write a function that returns an array with the size of each blob o…
#flood-fill #bfs #dfs #matrix
- CS fundamentals and algorithmsShort answerShopee
Purpose of virtual memory
Someone asks you, "If a device has plenty of physical memory, why do we even need virtual memory?" How would you answer?
#virtual-memory #paging #mmap #jetsam
- CS fundamentals and algorithmsShort answerAlibaba Group
Deduplicating beyond memory
You have a 1TB log file with one URL per line and need to remove duplicate URLs, but you only have 1GB of memory. How do you do it?
#external-memory #hash-partition #bloom-filter #dedupe
- CS fundamentals and algorithmsShort answer
Diff algorithms
When you apply a new snapshot to UICollectionViewDiffableDataSource, how does it compute the inserts, deletes, and moves? And why do item identifiers have to b…
#diffable-data-source #diff #myers #heckel
- CS fundamentals and algorithmsShort answer
Topological sort of dependencies
In an app split into 30 modules, the DI container initializes services in an order someone maintains by hand, and it crashed with "A needs B and B needs A." Wh…
#graph #topological-sort #dependency #cycle-detection
- CS fundamentals and algorithmsShort answer
Trie based autocomplete
You need search autocomplete that works offline: 500,000 candidate words, and on every keystroke you return the top 10 within 16ms. How do you design the data …
#trie #autocomplete #memory #search
- CS fundamentals and algorithmsShort answer
Prefix sum binary search
You're writing a custom vertical layout (a UICollectionViewLayout subclass) where every cell has a different height. layoutAttributesForElements(in rect:) gets…
#prefix-sum #binary-search #layout #scroll