Skip to main content

Apple Coding Interview Questions

Review this list of 58 Apple Coding Software Engineer interview questions and answers verified by hiring managers and candidates.
  • Apple logoAsked at Apple 
    Video answer for 'Edit distance'
    +32

    "from collections import deque def updateword(words, startword, end_word): if end_word not in words: return None # Early exit if end_word is not in the dictionary queue = deque([(start_word, 0)]) # (word, steps) visited = set([start_word]) # Keep track of visited words while queue: word, steps = queue.popleft() if word == end_word: return steps # Found the target word, return steps for i in range(len(word)): "

    叶 路. - "from collections import deque def updateword(words, startword, end_word): if end_word not in words: return None # Early exit if end_word is not in the dictionary queue = deque([(start_word, 0)]) # (word, steps) visited = set([start_word]) # Keep track of visited words while queue: word, steps = queue.popleft() if word == end_word: return steps # Found the target word, return steps for i in range(len(word)): "See full answer

    Software Engineer
    Coding
    +3 more
  • Apple logoAsked at Apple 
    +36

    "Was this for an entry level engineer role?"

    Yeshwanth D. - "Was this for an entry level engineer role?"See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    +38

    "def is_palindrome(s: str) -> bool: new = '' for a in s: if a.isalpha() or a.isdigit(): new += a.lower() return (new == new[::-1]) debug your code below print(is_palindrome('abcba')) `"

    Anonymous Roadrunner - "def is_palindrome(s: str) -> bool: new = '' for a in s: if a.isalpha() or a.isdigit(): new += a.lower() return (new == new[::-1]) debug your code below print(is_palindrome('abcba')) `"See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    Video answer for 'Find the container with the maximum volume of water.'

    "int getMaxWater(vector& nums) { int n = nums.size(); int mx = INT_MIN; int i=0, j=n-1; while(i<j) { int water = (j - i) * min(nums[i], nums[j]); mx = max(mx, water); if(nums[i] < nums[j]){ i++; } else { j--; } } return mx; } `"

    Richard W. - "int getMaxWater(vector& nums) { int n = nums.size(); int mx = INT_MIN; int i=0, j=n-1; while(i<j) { int water = (j - i) * min(nums[i], nums[j]); mx = max(mx, water); if(nums[i] < nums[j]){ i++; } else { j--; } } return mx; } `"See full answer

    Software Engineer
    Coding
    +3 more
  • Apple logoAsked at Apple 
    +24

    "We can use dictionary to store cache items so that our read / write operations will be O(1). Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1) Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"

    Alfred O. - "We can use dictionary to store cache items so that our read / write operations will be O(1). Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1) Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"See full answer

    Software Engineer
    Coding
    +6 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • Apple logoAsked at Apple 

    "This is a geometric variation of the "Sliding Window" technique. The core challenge is converting a 2D coordinate problem into a 1D linear problem using angles. The standard approach is the Angular Sweep. By converting the Cartesian coordinates (x,y) of every tree into Polar coordinates (specifically the angle θ), we can process the trees based on the direction they lie in relative to the observer. The Strategy Coordinate Translation: Calculate the relative coordinates (Δx,Δy) for"

    Ashish D. - "This is a geometric variation of the "Sliding Window" technique. The core challenge is converting a 2D coordinate problem into a 1D linear problem using angles. The standard approach is the Angular Sweep. By converting the Cartesian coordinates (x,y) of every tree into Polar coordinates (specifically the angle θ), we can process the trees based on the direction they lie in relative to the observer. The Strategy Coordinate Translation: Calculate the relative coordinates (Δx,Δy) for"See full answer

    Software Engineer
    Coding
    +1 more
  • +1

    " Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between: Skipping the current house and taking the maximum money stolen up to the previous house. Robbing the current house and adding its value to the maximum money stolen up to the house two steps back. package main import ( "fmt" ) // rob function calculates the maximum money a robber can steal func maxRob(nums []int) int { ln"

    VContaineers - " Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between: Skipping the current house and taking the maximum money stolen up to the previous house. Robbing the current house and adding its value to the maximum money stolen up to the house two steps back. package main import ( "fmt" ) // rob function calculates the maximum money a robber can steal func maxRob(nums []int) int { ln"See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    +26

    "we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"

    Kishor J. - "we can use two pointer + set like maintain i,j and also insert jth character to set like while set size is equal to our window j-i+1 then maximize our answer and increase jth pointer till last index"See full answer

    Software Engineer
    Coding
    +4 more
  • +11

    "Would be better to adjust resolution in the video player directly."

    Anonymous Prawn - "Would be better to adjust resolution in the video player directly."See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 

    "\# An program that prints out the peak elements in a list of integers. Pseudocode: 1. Define a function that takes a list of integers as input. 2. Initialize an empty list to store the peak elements. 3. Loop through the list of integers. 4. For each element, check if it is greater than its neighbors. 5. If it is, add it to the list of peak elements. 6. Return the list of peak elements. def findpeakelements(nums): if not nums: return [] peaks = [] n = len(nums"

    Frederick K. - "\# An program that prints out the peak elements in a list of integers. Pseudocode: 1. Define a function that takes a list of integers as input. 2. Initialize an empty list to store the peak elements. 3. Loop through the list of integers. 4. For each element, check if it is greater than its neighbors. 5. If it is, add it to the list of peak elements. 6. Return the list of peak elements. def findpeakelements(nums): if not nums: return [] peaks = [] n = len(nums"See full answer

    Software Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 

    "Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."

    Gaston B. - "Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    +26

    "Two pointers sub-routine from typing import List def reverse_words(arr: List[str]) -> List[str]: size = len(arr) #reverse whole array reversesubarr(arr, 0, size-1) #reverse each word start, end = 0, 0 for i in range(size): if arr[i].isspace() or i == size-1: end = i-1 if i != size-1 else i reversesubarr(arr, start, end) start = i+1 return arr def reversesubarr(array, start, end): print(array, start,"

    Nicolás N. - "Two pointers sub-routine from typing import List def reverse_words(arr: List[str]) -> List[str]: size = len(arr) #reverse whole array reversesubarr(arr, 0, size-1) #reverse each word start, end = 0, 0 for i in range(size): if arr[i].isspace() or i == size-1: end = i-1 if i != size-1 else i reversesubarr(arr, start, end) start = i+1 return arr def reversesubarr(array, start, end): print(array, start,"See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    +20

    " open = ['(','{','['] close = [')','}',']'] def is_valid(s: str) -> bool: pass # your code goes here n = len(s) if n == 0: return True elif n == 1: return False valid = (s[0] == '(' and s[1] == ')') or \ (s[0] == '{' and s[1] == '}') or \ (s[0] == '[' and s[1] == ']') if valid: return valid & is_valid(s[2:n]) else : valid = (s[0] == '(' and s[-1] == ')') or \ (s[0] == '"

    Cagdas A. - " open = ['(','{','['] close = [')','}',']'] def is_valid(s: str) -> bool: pass # your code goes here n = len(s) if n == 0: return True elif n == 1: return False valid = (s[0] == '(' and s[1] == ')') or \ (s[0] == '{' and s[1] == '}') or \ (s[0] == '[' and s[1] == ']') if valid: return valid & is_valid(s[2:n]) else : valid = (s[0] == '(' and s[-1] == ')') or \ (s[0] == '"See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    Video answer for 'Move all zeros to the end of an array.'
    +59

    "Initialize left pointer: Set a left pointer left to 0. Iterate through the array: Iterate through the array from left to right. If the current element is not 0, swap it with the element at the left pointer and increment left. Time complexity: O(n). The loop iterates through the entire array once, making it linear time. Space complexity: O(1). The algorithm operates in-place, modifying the input array directly without using additional data structures. "

    Avon T. - "Initialize left pointer: Set a left pointer left to 0. Iterate through the array: Iterate through the array from left to right. If the current element is not 0, swap it with the element at the left pointer and increment left. Time complexity: O(n). The loop iterates through the entire array once, making it linear time. Space complexity: O(1). The algorithm operates in-place, modifying the input array directly without using additional data structures. "See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    +5

    "DFS with check of an already seen node in the graph would work from collections import deque, defaultdict from typing import List def iscourseloopdfs(idcourse: int, graph: defaultdict[list]) -> bool: stack = deque([(id_course)]) seen_courses = set() while stack: print(stack) curr_course = stack.pop() if currcourse in seencourses: return True seencourses.add(currcourse) for dependency in graph[curr_course]: "

    Gabriele G. - "DFS with check of an already seen node in the graph would work from collections import deque, defaultdict from typing import List def iscourseloopdfs(idcourse: int, graph: defaultdict[list]) -> bool: stack = deque([(id_course)]) seen_courses = set() while stack: print(stack) curr_course = stack.pop() if currcourse in seencourses: return True seencourses.add(currcourse) for dependency in graph[curr_course]: "See full answer

    Software Engineer
    Coding
    +4 more
  • +13

    "public static int maxProfitGreedy(int[] stockPrices) { int maxProfit = 0; for(int i = 1; i todayPrice) { maxProfit += tomorrowPrice - todayPrice; } } return maxProfit; } "

    Laksitha R. - "public static int maxProfitGreedy(int[] stockPrices) { int maxProfit = 0; for(int i = 1; i todayPrice) { maxProfit += tomorrowPrice - todayPrice; } } return maxProfit; } "See full answer

    Software Engineer
    Coding
    +4 more
  • Apple logoAsked at Apple 
    Video answer for 'Product of Array Except Self'
    +58

    "If 0's aren't a concern, couldn't we just multiply all numbers. and then divide product by each number in the list ? if there's more than one zero, then we just return an array of 0s if there's one zero, then we just replace 0 with product and rest 0s. what am i missing?"

    Sachin R. - "If 0's aren't a concern, couldn't we just multiply all numbers. and then divide product by each number in the list ? if there's more than one zero, then we just return an array of 0s if there's one zero, then we just replace 0 with product and rest 0s. what am i missing?"See full answer

    Software Engineer
    Coding
    +3 more
  • "Use Dutch National Flag Algorithm to solve the problem"

    Sireesha R. - "Use Dutch National Flag Algorithm to solve the problem"See full answer

    Software Engineer
    Coding
    +1 more
  • Apple logoAsked at Apple 
    +47

    "function twoSum(nums, target) { const n = nums.length const map = new Map() for (let i=0; i<n; i++) { if (map.has(nums[i])) return [map.get(nums[i]), i] const diff = target - nums[i] map.set(diff, i) } return [] } `"

    Maciej Z. - "function twoSum(nums, target) { const n = nums.length const map = new Map() for (let i=0; i<n; i++) { if (map.has(nums[i])) return [map.get(nums[i]), i] const diff = target - nums[i] map.set(diff, i) } return [] } `"See full answer

    Software Engineer
    Coding
    +5 more
  • "First of all, stack and heap memory are abstraction on top of the hardware by the compiler. The hardware is not aware of stack and heap memory. There is only a single piece of memory that a program has access to. The compiler creates the concepts of stack and heap memory to run the programs efficiently. Programs use stack memory to store local variables and a few important register values such as frame pointer and return address for program counter. This makes it easier for the compiler to gene"

    Stanley Y. - "First of all, stack and heap memory are abstraction on top of the hardware by the compiler. The hardware is not aware of stack and heap memory. There is only a single piece of memory that a program has access to. The compiler creates the concepts of stack and heap memory to run the programs efficiently. Programs use stack memory to store local variables and a few important register values such as frame pointer and return address for program counter. This makes it easier for the compiler to gene"See full answer

    Software Engineer
    Coding
    +2 more
Showing 1-20 of 58