Apple Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
Find Maximum Sum of Contiguous Subarray Length k
Scenario Monitoring website traffic and needing the highest traffic within any fixed-length time window. Question Given an array of positive integers ...
Remove shortest subarray to sort array
Given an integer array nums (length up to 2×10^5), return the shortest subarray [L,R] you can remove so that the remaining elements form a non‑decreas...
Find longest uniform substring after k replacements
Given a string s (ASCII, length up to 2e5) and integer k (0 ≤ k ≤ |s|), return the length of the longest substring that can be turned into all the sam...
Compute optimal matrix-chain multiplication order
Matrix Chain Multiplication: Optimal Parenthesization and Analysis You are given five matrices to multiply: A1 (10×30), A2 (30×5), A3 (5×60), A4 (60×2...
Sort and merge string lists by length
Given two unsorted lists of strings, return a single list sorted by ascending string length. Specify your tie-breaking rule for equal-length strings (...
Compute minimum required meeting rooms
Given a list of meeting time intervals [start, end) for many events, determine the minimum number of rooms required so no meetings overlap in the same...
Implement deep clone for complex objects
Implement a deep-clone function for nested objects in JavaScript (or a language of your choice) without using JSON serialization or third-party librar...
Refactor rock–paper–scissors for config and ties
Refactor an existing Rock–Paper–Scissors tournament with three robot players so that the number of rounds is configurable and the system also tracks t...
Find top-k frequent elements efficiently
Given an array (or stream) of integers and an integer k, return any ordering of the k most frequent values. Implement a solution using a heap and disc...
Design a rolling five-minute hit counter
Design an in-memory hit counter that supports: ( 1) recordHit(timestamp) to log an event, and ( 2) getCountLast5Minutes(now) to return the number of e...
Design card deck with shuffle and order
Design a playing-card deck library with two methods: shuffle() to return a uniformly random permutation of a standard 52-card deck, and order() to ret...
Implement DFS for connected components
Given an undirected graph with n nodes (1 ≤ n ≤ 200, 000) and an edge list, implement depth-first search to compute (a) the number of connected compon...
Implement rotation, LRU cache, streaming median, cycle detection
Complete the following coding tasks. For each, provide code, justify time/space complexity, and describe edge cases: 1) Image rotation: Given an n×n i...
Implement bag-of-words similarity search from scratch
Implement a bag-of-words–based text similarity search engine from scratch. Write code that: ( 1) tokenizes text (lowercasing, punctuation handling, Un...
Compute island size in grid
Given an m x n binary matrix grid of 0s (water) and 1s (land), where an island is a group of 1s connected 4-directionally, implement sizeOfIsland(grid...
Compute top three scores per student
You are given a list of (student_id, score) records. Return, for each student, their highest three scores in descending order. First, describe and imp...
Design a snapshotable key-value store
Design and implement a snapshotable key–value map supporting the following APIs: - S(key, value): set the current value of a string key to a string va...
Find Smallest Missing Positive Integer in O(n) Time
Scenario LeetCode-style algorithm phone interview Question Implement a function that returns the smallest missing positive integer in an unsorted inte...
Maximize funds with capital-gated projects
You start with initial funds W and may undertake at most K projects. Each project i has a required capital C[i] and yields profit P[i]; you can only s...