Apple Coding Interview Questions: OA, Phone Screen & Onsite | New Grad, ICT2, ICT3 & Intern
Apple is one of the most prestigious technology companies in the world and consistently ranks among the top destinations for software engineers. Unlike Google or Meta, Apple's hiring process is highly decentralised — each team designs its own interviews. This means question style and difficulty can vary significantly between the iOS team, Core OS, Siri, iCloud, and Apple Silicon teams.
What remains consistent across all Apple SWE interviews is the emphasis on clean, defensive code, edge case handling, memory awareness, and strong behavioural fit. Apple places more weight on behavioural interviews than most product companies — they want engineers who align with their values of craftsmanship, privacy, and long-term ownership.
This guide covers Apple's full hiring process and 50 actual coding problems reported by candidates for New Grad, ICT2, ICT3, and Intern tracks across 2024–2026.
Apple's Hiring Process for SWE Roles (2026)
1. Online Application
- Apply via jobs.apple.com. Apple recruits heavily through campus programs and internal referrals.
- Tip: Tailor your resume to the specific team (iOS, macOS, iCloud, Siri, etc.). Mentioning experience with Swift, Objective-C, or low-level systems gets immediate attention from Apple recruiters.
2. Recruiter Screen — 20–30 minutes
- Non-technical call covering your background, motivation for Apple, and alignment with the team's product area.
- Tip: Research the team you are applying to. Saying "I want to work on CoreML because I've shipped an on-device inference model" is far stronger than "I love Apple products."
3. Technical Phone Screen — 45–60 minutes, 1–2 rounds
- Conducted on CoderPad or a shared coding environment. 1–2 medium-difficulty problems.
- Apple phone screens are slower-paced than Meta or Google — interviewers allow more thinking time.
- Tip: Write clean, well-named code from the start. Apple interviewers are known to comment on code style mid-interview. Treat it like production code.
4. Virtual Onsite Loop — 4–5 Rounds (45–60 min each)
- Coding Rounds (2–3): 1–2 problems per round. Medium difficulty. High emphasis on edge case correctness.
- System Design (ICT3+): Low-level or high-level depending on seniority. Apple often asks practical system design (URL shortener, notification system, caching layer).
- Behavioural Rounds (1–2): Focused on collaboration, ownership, conflict resolution, and Apple's culture of craftsmanship.
- Tip: Apple interviewers frequently deep-dive into your resume. Be prepared to talk deeply about every project you list — including architectural decisions and tradeoffs you made.
5. Hiring Committee & Team Matching
- HC reviews all round feedback. Successful candidates may meet 1–3 potential hiring managers before a final offer.
- Tip: Response times at Apple can be slower than other FAANG companies — 2–4 weeks after the final round is normal. Don't panic.
Preparation Resources
Part 1 — Online Assessment (OA)
Apple's OA is hosted on HackerRank or CodeSignal. You get 2 medium problems in 90 minutes. Questions focus on binary search, two pointers, and string manipulation. Unlike Google's OA, Apple's OA is less standardised — question difficulty varies by team.
1. Minimum Characters to Make a Palindrome Medium
Given a string s, return the minimum number of characters you need to add (at any position) to make it a palindrome.
Input: s = "abcd"
Output: 3
Input: s = "racecar"
Output: 0 (already a palindrome)
Approach: Answer equals len(s) - LPS(s) where LPS is the Longest Palindromic Subsequence. Find LPS using DP on lcs(s, reversed(s)).
Complexity: Time O(n²) · Space O(n²)
Follow-up: What if you can only add characters to the front or back?
2. Palindrome Index Easy
Given a string, find the index of one character that can be removed to make it a palindrome. Return -1 if already a palindrome or if no single removal works.
Input: s = "bcbc"
Output: 0 (remove index 0 → "cbc")
Input: s = "racecar"
Output: -1
Approach: Two pointers from both ends. On mismatch at (l, r), try removing index l or r and check if the remaining substring is a palindrome.
Complexity: Time O(n) · Space O(1)
Follow-up: Valid Palindrome II (LeetCode 680) is the direct equivalent.
3. Best Time to Buy and Sell Stock Easy
Find the maximum profit from one buy and one sell. You must buy before you sell.
Input: prices = [7,1,5,3,6,4]
Output: 5 (buy at 1, sell at 6)
Input: prices = [7,6,4,3,1]
Output: 0
Approach: Track running minimum. At each price, compute price - min_so_far and update global max profit.
Complexity: Time O(n) · Space O(1)
Follow-up: Best Time to Buy and Sell Stock II (LeetCode 122) — unlimited transactions.
4. Maximum Length of Mountain in Array Medium
A mountain subarray has at least 3 elements, strictly increases to a peak, then strictly decreases. Find the length of the longest such subarray.
Input: arr = [2,1,4,7,3,2,5]
Output: 5 (subarray [1,4,7,3,2])
Approach: For each potential peak, expand left while ascending and right while descending. Track the max total length.
Complexity: Time O(n) · Space O(1)
Follow-up: Count the number of distinct mountains in the array.
5. Jump Game Medium
Each element is your max jump length from that position. Determine if you can reach the last index.
Input: nums = [2,3,1,1,4]
Output: true
Input: nums = [3,2,1,0,4]
Output: false
Approach: Track the maximum reachable index. If current index ever exceeds it, return false. Update maxReach = max(maxReach, i + nums[i]).
Complexity: Time O(n) · Space O(1)
Follow-up: Jump Game II (LeetCode 45) — minimum jumps to reach the end.
6. Reorganize String Medium
Rearrange characters in a string so no two adjacent characters are the same. Return the rearranged string, or "" if impossible.
Input: s = "aab"
Output: "aba"
Input: s = "aaab"
Output: ""
Approach: If any character's count exceeds (n+1)/2, return "". Use a max-heap — repeatedly pop the two most frequent characters and append them alternately.
Complexity: Time O(n log k) · Space O(k) where k is unique chars
Follow-up: Task Scheduler (LeetCode 621) — minimum intervals with cooldown.
Part 2 — Phone Screen
Apple's phone screen is 45–60 minutes on CoderPad. You get 1–2 medium problems. Apple interviewers allow more thinking time than other FAANG — they value the quality of your reasoning. Write clean, production-quality code from the first line.
7. Container With Most Water Medium
Given n vertical lines with heights, find two lines that form a container holding the most water.
Input: height = [1,8,6,2,5,4,8,3,7]
Output: 49
Approach: Two pointers at both ends. Move the pointer at the shorter line inward. Water = min(height[l], height[r]) x (r - l). Update max at each step.
Complexity: Time O(n) · Space O(1)
Follow-up: Trapping Rain Water (LeetCode 42) — each bar traps water independently.
8. Merge Intervals Medium
Given an array of intervals, merge all overlapping intervals.
Input: [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Approach: Sort by start time. Extend the last interval's end if the current start overlaps; otherwise push a new entry.
Complexity: Time O(n log n) · Space O(n)
Follow-up: Insert Interval (LeetCode 57) — insert into an already sorted non-overlapping list.
9. Reverse Linked List II Medium
Reverse a linked list from position left to position right in one pass. Positions are 1-indexed.
Input: head = [1,2,3,4,5], left = 2, right = 4
Output: [1,4,3,2,5]
Approach: Use a dummy head. Navigate to the node before left. Perform in-place reversal using the "insert at front" technique for right - left iterations.
Complexity: Time O(n) · Space O(1)
Follow-up: Reverse Nodes in k-Group (LeetCode 25).
10. Path Sum II Medium
Return all root-to-leaf paths in a binary tree where the path sum equals a given target.
Input: root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
Output: [[5,4,11,2],[5,8,4,5]]
Approach: DFS backtracking. Track the current path and remaining sum. When a leaf is reached and remaining sum equals zero, add the current path copy to results.
Complexity: Time O(n) · Space O(h) recursion stack
Follow-up: Path Sum III (LeetCode 437) — paths don't need to start or end at root/leaf.
11. Lowest Common Ancestor of a Binary Tree Medium
Find the lowest common ancestor (LCA) of two nodes in a binary tree. The LCA is the deepest node that has both p and q as descendants.
Input: root = [3,5,1,6,2,0,8], p = 5, q = 1
Output: 3
Approach: Post-order DFS. If the current node equals p or q, return it. If both left and right return non-null, the current node is the LCA.
Complexity: Time O(n) · Space O(h)
Follow-up: LCA of Deep Nodes (LeetCode 1123) — LCA of the deepest leaves.
12. Remove Nth Node From End of List Medium
Remove the nth node from the end of a linked list in one pass. Return the head.
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]
Approach: Two pointers with n+1 gap. Advance the fast pointer n+1 steps. Move both until fast reaches null. Remove slow.next.
Complexity: Time O(n) · Space O(1)
Follow-up: Remove all nodes with a given value (LeetCode 203).
13. Decode String Medium
Given an encoded string like 3[a2[c]], decode it. Encoding rule: k[encoded_string] means the string is repeated k times.
Input: s = "3[a2[c]]"
Output: "accaccacc"
Approach: Use a stack. Push the current string and repeat count when a [ is seen. On ], pop and repeat the current segment the stored count times.
Complexity: Time O(n * max_k) · Space O(n)
Follow-up: Handle nested brackets with multiple digits (e.g., 100[a]).
Part 3 — Onsite / Virtual Onsite
The onsite has 4–5 rounds. Coding rounds (2–3) have 1–2 problems each. Expect medium problems with strict edge-case scrutiny. System design is required for ICT3 and above. Behavioural rounds focus on ownership and craftsmanship.
14. Trapping Rain Water Hard
Given an elevation map, compute how much water it can trap after raining.
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Approach: Two pointers. Track left_max and right_max. Move the pointer at the lower max inward — water trapped at that cell = max_height - current_height.
Complexity: Time O(n) · Space O(1)
Follow-up: Trapping Rain Water II (LeetCode 407) — 3D version using a min-heap BFS.
15. LRU Cache Medium
Design a data structure for LRU Cache supporting get(key) and put(key, value) in O(1) time.
Input: capacity = 2
put(1,1), put(2,2), get(1) → 1, put(3,3), get(2) → -1
Approach: Doubly linked list + hash map. Most recently used at head, least recently used at tail. On access, move node to head. On eviction, remove tail.
Complexity: Time O(1) for both operations · Space O(capacity)
Follow-up: LFU Cache (LeetCode 460) — evict the least frequently used.
16. Binary Tree Level Order Traversal Medium
Return the level-order traversal of a binary tree's nodes (left to right, level by level).
Input: root = [3,9,20,null,null,15,7]
Output: [[3],[9,20],[15,7]]
Approach: BFS with a queue. At each level, process all nodes currently in the queue, collect their values, and enqueue their children.
Complexity: Time O(n) · Space O(n)
Follow-up: Zigzag Level Order (LeetCode 103) — alternate left-right direction per level.
17. Serialize and Deserialize Binary Tree Hard
Design an algorithm to serialize a binary tree to a string and deserialize it back to the original structure.
Input: root = [1,2,3,null,null,4,5]
Output: Deserialized tree matches original
Approach: BFS serialization — encode level by level with "null" markers. Deserialize by reconstructing level by level using a queue.
Complexity: Time O(n) · Space O(n)
Follow-up: Serialize an N-ary tree — preorder DFS with child count per node.
18. Number of Islands Medium
Count the number of islands in an m x n binary grid. An island is formed by connecting adjacent '1's horizontally or vertically.
Input: grid = [["1","1","0"],["0","1","0"],["0","0","1"]]
Output: 2
Approach: DFS flood-fill. For each unvisited '1', start a DFS marking all connected land cells visited. Count each DFS call as one island.
Complexity: Time O(m x n) · Space O(m x n)
Follow-up: Number of Distinct Islands (LeetCode 694) — track shape of each island.
19. Spiral Matrix Medium
Return all elements of an m x n matrix in spiral order.
Input: matrix = [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
Approach: Use four boundary pointers (top, bottom, left, right). Traverse right, down, left, up. Shrink boundaries after each direction pass.
Complexity: Time O(m x n) · Space O(1) (excluding output)
Follow-up: Spiral Matrix II (LeetCode 59) — fill a matrix in spiral order.
20. Rotate Image Medium
Rotate an n x n matrix 90 degrees clockwise in-place.
Input: [[1,2,3],[4,5,6],[7,8,9]]
Output: [[7,4,1],[8,5,2],[9,6,3]]
Approach: Two steps in-place — first transpose the matrix (swap matrix[i][j] with matrix[j][i]), then reverse each row.
Complexity: Time O(n²) · Space O(1)
Follow-up: Rotate 90 degrees counter-clockwise — reverse each row first, then transpose.
21. Minimum Window Substring Hard
Find the minimum window substring of s that contains all characters of t.
Input: s = "ADOBECODEBANC", t = "ABC"
Output: "BANC"
Approach: Sliding window with two frequency maps. Expand right until all chars of t are covered, then shrink left to minimise window size while maintaining coverage.
Complexity: Time O(|s| + |t|) · Space O(|t|)
Follow-up: Find all minimum windows, not just one.
22. Course Schedule Medium
Given numCourses and a list of prerequisites, determine if it is possible to finish all courses (detect cycle in directed graph).
Input: numCourses = 2, prerequisites = [[1,0]]
Output: true
Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
Output: false
Approach: DFS with three states (unvisited, visiting, visited). If you revisit a node in the "visiting" state, a cycle exists.
Complexity: Time O(V + E) · Space O(V + E)
Follow-up: Course Schedule II (LeetCode 210) — return the topological order.
23. Convert Sorted Array to Binary Search Tree Easy
Convert a sorted integer array to a height-balanced BST.
Input: nums = [-10,-3,0,5,9]
Output: [0,-3,9,-10,null,5] (or similar valid balanced BST)
Approach: Recursively pick the middle element as root. Build left subtree from left half, right subtree from right half.
Complexity: Time O(n) · Space O(log n)
Follow-up: Convert Sorted List to Binary Search Tree (LeetCode 109) — input is a linked list.
24. 3Sum Medium
Find all unique triplets in the array that sum to zero. No duplicate triplets in the result.
Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]
Approach: Sort the array. For each element nums[i], use two pointers to find pairs summing to -nums[i]. Skip duplicates.
Complexity: Time O(n²) · Space O(1) excluding output
Follow-up: 4Sum (LeetCode 18) — add one more outer loop.
25. Coin Change Medium
Given coin denominations and an amount, find the minimum number of coins needed to make that amount. Return -1 if impossible.
Input: coins = [1,5,11], amount = 15
Output: 3 (5 + 5 + 5)
Approach: Bottom-up DP. dp[i] = min coins for amount i. For each amount from 1 to target, try each coin: dp[i] = min(dp[i], dp[i - coin] + 1).
Complexity: Time O(amount x coins) · Space O(amount)
Follow-up: Coin Change II (LeetCode 518) — count the number of combinations.
26. Word Break Medium
Return true if string s can be segmented into space-separated dictionary words.
Input: s = "leetcode", wordDict = ["leet","code"]
Output: true
Approach: DP where dp[i] = true if s[0..i-1] can be segmented. For each i, check all j < i where dp[j] is true and s[j..i-1] is in the dict.
Complexity: Time O(n²) · Space O(n)
Follow-up: Word Break II (LeetCode 140) — return all valid segmentations.
27. Maximum Subarray Medium
Find the contiguous subarray with the largest sum.
Input: nums = [-2,1,-3,4,-1,2,1,-5,4]
Output: 6 (subarray [4,-1,2,1])
Approach: Kadane's algorithm. Track current_sum. At each element, current_sum = max(num, current_sum + num). Update global max.
Complexity: Time O(n) · Space O(1)
Follow-up: Return the actual subarray, not just the sum.
28. Merge K Sorted Lists Hard
Merge k sorted linked lists into one sorted linked list.
Input: lists = [[1,4,5],[1,3,4],[2,6]]
Output: [1,1,2,3,4,4,5,6]
Approach: Min-heap storing (value, list_index, node). Pop minimum, push next node from that list. Divide and conquer pair-wise merge is an alternative.
Complexity: Time O(N log k) · Space O(k)
Follow-up: What if lists are too large for memory? External merge sort.
29. Product of Array Except Self Medium
Return an array where output[i] is the product of all elements except nums[i]. No division allowed.
Input: nums = [1,2,3,4]
Output: [24,12,8,6]
Approach: Two passes — left prefix product pass, then right suffix product pass in-place.
Complexity: Time O(n) · Space O(1) excluding output
Follow-up: Handle zeros in the array (single zero vs multiple zeros).
30. Clone Graph Medium
Return a deep copy of a connected undirected graph.
Input: adjList = [[2,4],[1,3],[2,4],[1,3]]
Output: Deep copy with identical adjacency structure
Approach: BFS with a hash map from original node to its clone. For each neighbour, create the clone if not seen, then add it to the current clone's neighbours.
Complexity: Time O(V + E) · Space O(V)
Follow-up: What if the graph has disconnected components?
31. Group Anagrams Medium
Group strings that are anagrams of each other. Return the groups in any order.
Input: strs = ["eat","tea","tan","ate","nat","bat"]
Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
Approach: Hash map keyed by each string's sorted form. All anagrams share the same sorted key.
Complexity: Time O(n * k log k) · Space O(n * k)
Follow-up: Use character frequency tuple as key instead of sorted string for O(n*k) time.
32. Longest Common Subsequence Medium
Find the length of the longest common subsequence of two strings.
Input: text1 = "abcde", text2 = "ace"
Output: 3 ("ace")
Approach: 2D DP. If chars match: dp[i][j] = dp[i-1][j-1] + 1. Otherwise: dp[i][j] = max(dp[i-1][j], dp[i][j-1]).
Complexity: Time O(m x n) · Space O(m x n), optimisable to O(min(m,n))
Follow-up: Shortest Common Supersequence (LeetCode 1092) — smallest string containing both as subsequences.
33. Kth Largest Element in an Array Medium
Find the kth largest element in an unsorted array.
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
Approach: Min-heap of size k — push elements, pop when size exceeds k. The heap root is the answer. Quickselect achieves O(n) average.
Complexity: Time O(n log k) with heap · Space O(k)
Follow-up: What if the array is a stream of unknown length?
34. Implement Stack Using Min Stack Easy
Design a stack that supports push, pop, top, and retrieving the minimum element, all in O(1).
Input: push(-2), push(0), push(-3), getMin() → -3, pop(), top() → 0, getMin() → -2
Approach: Maintain a secondary min-stack alongside the main stack. Push to the min-stack only when the new value is <= the current minimum.
Complexity: Time O(1) for all operations · Space O(n)
Follow-up: Max Stack (LeetCode 716) — support both max and pop-max.
35. Valid Parentheses Easy
Check if a string of brackets is valid — every open bracket must be closed in the correct order.
Input: s = "()[]{}"
Output: true
Input: s = "(]"
Output: false
Approach: Stack. Push open brackets. On close bracket, check if the stack top is the matching open bracket. At the end, stack must be empty.
Complexity: Time O(n) · Space O(n)
Follow-up: Minimum Remove to Make Valid Parentheses (LeetCode 1249).
36. Copy List with Random Pointer Medium
Deep copy a linked list where each node has a next pointer and a random pointer.
Input: head = [[7,null],[13,0],[11,4],[10,2],[1,0]]
Output: Identical deep copy
Approach: Interleave cloned nodes after originals, assign random pointers using the interleaved structure, then separate the two lists. O(1) space excluding output.
Complexity: Time O(n) · Space O(1)
Follow-up: Use a hash map for a cleaner O(n) space solution.
37. String to Integer (atoi) Medium
Implement the myAtoi function that converts a string to a 32-bit signed integer. Handle leading whitespace, sign, overflow, and non-digit characters.
Input: s = " -42"
Output: -42
Input: s = "4193 with words"
Output: 4193
Approach: Skip whitespace, read sign, build integer digit by digit, clamp to INT_MIN/INT_MAX on overflow.
Complexity: Time O(n) · Space O(1)
Follow-up: Apple uses this question to test defensive coding — always verify every edge case explicitly.
38. Find Middle of Linked List Easy
Find the middle node of a linked list. If two middle nodes exist, return the second.
Input: head = [1,2,3,4,5]
Output: [3,4,5]
Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Approach: Slow and fast pointers. Fast moves 2 steps, slow moves 1. When fast reaches the end, slow is at the middle.
Complexity: Time O(n) · Space O(1)
Follow-up: Find the node at one-third of the list length.
39. Detect Cycle in Linked List Easy
Given the head of a linked list, determine if it has a cycle.
Input: head = [3,2,0,-4], pos = 1 (tail connects to node at index 1)
Output: true
Approach: Floyd's tortoise and hare. Slow pointer moves 1 step, fast moves 2. If they ever meet, there is a cycle.
Complexity: Time O(n) · Space O(1)
Follow-up: Linked List Cycle II (LeetCode 142) — find the entry point of the cycle.
40. N-Queens Hard
Place n queens on an n x n chessboard so no two queens attack each other. Return all distinct solutions.
Input: n = 4
Output: [[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
Approach: Backtracking row by row. Track columns, diagonals, and anti-diagonals in sets. At each row, try all valid columns and recurse.
Complexity: Time O(n!) · Space O(n)
Follow-up: N-Queens II (LeetCode 52) — return only the count of solutions.
41. Maximum Product Subarray Medium
Find the contiguous subarray that has the largest product.
Input: nums = [2,3,-2,4]
Output: 6 (subarray [2,3])
Approach: Track both current max and min (since a negative * negative = positive). At each step: max_prod = max(num, max_prod*num, min_prod*num).
Complexity: Time O(n) · Space O(1)
Follow-up: What if the array contains zeros? Reset max/min to the current element.
42. Wildcard Matching Hard
Given string s and pattern p with ? (matches any single char) and * (matches any sequence), return true if p matches s entirely.
Input: s = "adceb", p = "*a*b"
Output: true
Input: s = "aab", p = "c*a*b"
Output: false
Approach: 2D DP. dp[i][j] = true if s[0..i-1] matches p[0..j-1]. Handle * as matching empty or one more char.
Complexity: Time O(m x n) · Space O(m x n)
Follow-up: Regular Expression Matching (LeetCode 10) — . and * with different semantics.
43. Permutations Medium
Return all possible permutations of a distinct integer array.
Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Approach: Backtracking with a used-set. At each step, try all unused elements. Add the current permutation to results when its length equals nums.length.
Complexity: Time O(n! x n) · Space O(n)
Follow-up: Permutations II (LeetCode 47) — handle duplicate numbers.
44. Word Search Medium
Find if a word exists in a 2D board as a horizontally/vertically connected sequence without reusing cells.
Input: board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED"
Output: true
Approach: DFS backtracking. For each cell matching word[0], DFS in four directions. Mark cells visited by temporarily altering the value; restore after recursion.
Complexity: Time O(m x n x 4^L) · Space O(L)
Follow-up: Word Search II (LeetCode 212) — find all words from a list using a Trie.
45. Alien Dictionary Hard
Given words sorted in an alien language, determine the character ordering. Return the order or "" if invalid.
Input: words = ["wrt","wrf","er","ett","rftt"]
Output: "wertf"
Approach: Compare adjacent words to extract ordering constraints. Build a directed graph, run topological sort. Return "" if a cycle is detected.
Complexity: Time O(C) where C is total characters · Space O(U) where U is unique chars
Follow-up: Return all valid orderings if multiple exist.
46. Insert Interval Medium
Insert a new interval into a sorted list of non-overlapping intervals, merging if necessary.
Input: intervals = [[1,3],[6,9]], newInterval = [2,5]
Output: [[1,5],[6,9]]
Approach: Add all intervals that end before newInterval starts. Merge all overlapping intervals into newInterval. Add remaining intervals.
Complexity: Time O(n) · Space O(n)
Follow-up: What if the intervals list is not sorted?
47. Minimum Cost to Connect Sticks Medium
Given sticks of various lengths, connect them all into one stick. The cost of connecting two sticks is their combined length. Find the minimum total cost.
Input: sticks = [2,4,3]
Output: 14 (connect 2+3=5, then 5+4=9, total 14)
Approach: Min-heap (Huffman coding). Always merge the two smallest sticks. Add the merged stick back. Sum all merge costs.
Complexity: Time O(n log n) · Space O(n)
Follow-up: This is identical to Huffman encoding — same greedy structure.
48. Search in Rotated Sorted Array Medium
Search a target in a rotated sorted array in O(log n) time.
Input: nums = [4,5,6,7,0,1,2], target = 0
Output: 4
Approach: Modified binary search. Determine which half is sorted. Check if target falls in the sorted half; if so, search there, otherwise search the other half.
Complexity: Time O(log n) · Space O(1)
Follow-up: Search in Rotated Sorted Array II (LeetCode 81) — handle duplicates.
49. Best Time to Buy and Sell Stock IV Hard
Find the maximum profit with at most k transactions. Must sell before buying again.
Input: k = 2, prices = [3,2,6,5,0,3]
Output: 7
Approach: DP with k x 2 states tracking (transaction_count, holding_stock). If k >= n/2, treat as unlimited transactions problem.
Complexity: Time O(n x k) · Space O(k)
Follow-up: Infinite transactions (LeetCode 122) — greedy, sum all positive differences.
50. LFU Cache Hard
Design a Least Frequently Used (LFU) Cache with O(1) get and put operations.
Input: capacity = 2
put(1,1), put(2,2), get(1) → 1, put(3,3), get(2) → -1, get(3) → 3
Approach: Three maps — key-to-value, key-to-frequency, frequency-to-ordered-set-of-keys. Track the minimum frequency. On eviction, remove the LRU key from the min-frequency bucket.
Complexity: Time O(1) for both operations · Space O(capacity)
Follow-up: LRU Cache (LeetCode 146) is the simpler prerequisite — solve it first.
Apple Interview Preparation Tips
- Defensive coding is non-negotiable: Apple interviewers expect null checks, empty input handling, and overflow guards. Write production-level code — not just "correct" code.
- Edge cases first: Before coding, list every edge case out loud. Apple interviewers track whether you proactively identify them.
- Memory awareness: Apple builds products with strict memory budgets. Be ready to discuss heap vs stack allocation, in-place vs auxiliary space, and why your chosen approach fits the constraints.
- Clean variable names: Avoid single-letter variables. Apple engineers read your code like a code review.
- Behavioural is weighted heavily: Apple's behavioural rounds are elimination rounds. Prepare STAR stories around ownership, disagreeing with a manager, shipping under pressure, and a time you improved a process.
- Team-specific prep: Apple interviews vary by team. Core OS teams lean toward systems and concurrency. Services teams lean toward distributed systems and APIs. iOS teams may ask Swift-specific patterns.
- No DP surprises: DP does appear at Apple unlike Meta's phone screen. Coin Change, Word Break, and LCS are all reported at onsite level.
Join Telegram group for any doubts & discussions!