Apple Coding & Algorithms Interview Questions
Practice the exact questions companies are asking right now.
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...
Implement TF-IDF scoring for documents
Problem Implement a simplified TF–IDF scorer. You are given: - A list of documents docs, where each document is a string. - A query string q. Tokeniza...
Write a generator for substring pattern matches
Problem Write a generator that scans a string and emits a value whenever a substring matches a given pattern. Input - A string s - A string pattern (n...
Solve interval, grid-fill, and heap tasks
You are asked to solve the following algorithmic problems. Problem 1: Concurrent users from online intervals You are given n inclusive time intervals ...
Implement most_frequent_key without using max()
Problem (Python OOP) You are given two classes. Parent precomputes frequency counts of items (as strings) from an input list. `python class Parent: ...
Solve three easy algorithm problems
You are given three independent algorithmic tasks. For each one, explain your approach (no need to run code). 1) Merge two sorted lists (integers inst...
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...
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...
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...
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...
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...
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...