Coding Interview Questions

Review this list of 374 coding interview questions and answers verified by hiring managers and candidates.
  • 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
  • "class TreeNode(var val: Int, var left: TreeNode? = null, var right: TreeNode? = null) fun isAverageOfDescendants(root: TreeNode?): Boolean { fun helper(node: TreeNode?): Triple { if (node == null) return Triple(0, 0, true) val (leftSum, leftCount, leftValid) = helper(node.left) val (rightSum, rightCount, rightValid) = helper(node.right) val totalSum = leftSum + rightSum val totalCount = leftCount + rightCount // If leaf n"

    Gaurav B. - "class TreeNode(var val: Int, var left: TreeNode? = null, var right: TreeNode? = null) fun isAverageOfDescendants(root: TreeNode?): Boolean { fun helper(node: TreeNode?): Triple { if (node == null) return Triple(0, 0, true) val (leftSum, leftCount, leftValid) = helper(node.left) val (rightSum, rightCount, rightValid) = helper(node.right) val totalSum = leftSum + rightSum val totalCount = leftCount + rightCount // If leaf n"See full answer

    Software Engineer
    Coding
    +1 more
  • Amazon logoAsked at Amazon 
    +3

    "Inorder traversal of the tree should be the solution for this problem."

    Balasubramanian R. - "Inorder traversal of the tree should be the solution for this problem."See full answer

    Software Engineer
    Coding
    +1 more
  • Google logoAsked at Google 
    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Edit distance'
    +18

    "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
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • Databricks logoAsked at Databricks 

    "Constraints: 4-direction moves; no mode switching (pick exactly one of {1=bicycle, 2=bike, 3=car, 4=bus} for the full trip). Per-mode search: If a mode’s per-step time/cost are uniform, run BFS on allowed cells. Then totaltime = steps × timeperstep, tie-break by steps × costper_step. If time/cost vary by cell (given matrices), run Dijkstra per mode minimizing (totaltime, totalcost) lexicographically. Maintain the best ⟨time, cost⟩ per cell; relax when the new pair is strictly better. S"

    Rahul J. - "Constraints: 4-direction moves; no mode switching (pick exactly one of {1=bicycle, 2=bike, 3=car, 4=bus} for the full trip). Per-mode search: If a mode’s per-step time/cost are uniform, run BFS on allowed cells. Then totaltime = steps × timeperstep, tie-break by steps × costper_step. If time/cost vary by cell (given matrices), run Dijkstra per mode minimizing (totaltime, totalcost) lexicographically. Maintain the best ⟨time, cost⟩ per cell; relax when the new pair is strictly better. S"See full answer

    Software Engineer
    Coding
    +1 more
  • Video answer for 'Employee Earnings.'
    +40

    "SELECT employees.first_name, managers.salary AS manager_salary FROM employees LEFT JOIN employees AS managers ON employees.manager_id = managers.id WHERE employees.salary > managers.salary `"

    Tiffany A. - "SELECT employees.first_name, managers.salary AS manager_salary FROM employees LEFT JOIN employees AS managers ON employees.manager_id = managers.id WHERE employees.salary > managers.salary `"See full answer

    Software Engineer
    Coding
    +4 more
  • +8

    "Answer: select fromcaller, count(DISTINCT tocallee) as num_calls from calls group by fromcaller having count(DISTINCT tocallee) >= 3 Setup: CREATE TABLE calls ( from_caller VARCHAR(20), to_callee VARCHAR(20) ); INSERT INTO calls (fromcaller, tocallee) VALUES ('Alice', 'Bob'), ('Charlie', 'Dave'), ('Alice', 'Frank'), ('Charlie', 'Heidi'), ('Charlie', 'Judy'); "

    KAI - "Answer: select fromcaller, count(DISTINCT tocallee) as num_calls from calls group by fromcaller having count(DISTINCT tocallee) >= 3 Setup: CREATE TABLE calls ( from_caller VARCHAR(20), to_callee VARCHAR(20) ); INSERT INTO calls (fromcaller, tocallee) VALUES ('Alice', 'Bob'), ('Charlie', 'Dave'), ('Alice', 'Frank'), ('Charlie', 'Heidi'), ('Charlie', 'Judy'); "See full answer

    Data Scientist
    Coding
    +3 more
  • LinkedIn logoAsked at LinkedIn 

    "Requirements and Goals Primary Goal:Store key-value pairs in a cache with efficient access (reads/writes). Evict items based on a certain “rank,” which might reflect popularity, frequency, or custom ranking logic. Functional Requirements:Put(key, value, rank): Insert or update a key with the given value and rank. Get(key): Retrieve the value associated with the key if it exists. Evict(): If the cache is at capacity, evict the item with the lowest rank (or according"

    Alvis F. - "Requirements and Goals Primary Goal:Store key-value pairs in a cache with efficient access (reads/writes). Evict items based on a certain “rank,” which might reflect popularity, frequency, or custom ranking logic. Functional Requirements:Put(key, value, rank): Insert or update a key with the given value and rank. Get(key): Retrieve the value associated with the key if it exists. Evict(): If the cache is at capacity, evict the item with the lowest rank (or according"See full answer

    Engineering Manager
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    +32

    "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
  • "Function signature for reference: def calculate(servers: List[int], k: int) -> int: ... To resolve this, you can use binary search considering left=0 and right=max(servers) * k so Example: servers=[1,4,5] First server handle 1 request in let's say 1 second, second 4 seconds and last 5 seconds. k=10 So I want to know the minimal time to process 10 requests Get the mid for timeline mid = (left+right)//2 -> mid is 25 Check how many we could process 25//1 = 25 25//4=6 25//5=5 so 25 + 6 +"

    Babaa - "Function signature for reference: def calculate(servers: List[int], k: int) -> int: ... To resolve this, you can use binary search considering left=0 and right=max(servers) * k so Example: servers=[1,4,5] First server handle 1 request in let's say 1 second, second 4 seconds and last 5 seconds. k=10 So I want to know the minimal time to process 10 requests Get the mid for timeline mid = (left+right)//2 -> mid is 25 Check how many we could process 25//1 = 25 25//4=6 25//5=5 so 25 + 6 +"See full answer

    Software Engineer
    Coding
  • 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

    Data Engineer
    Coding
    +3 more
  • IBM logoAsked at IBM 
    +52

    "SELECT MIN(id) AS id, TRIM(LOWER(email)) AS cleaned_email FROM users GROUP BY cleaned_email ORDER BY id `"

    Salome L. - "SELECT MIN(id) AS id, TRIM(LOWER(email)) AS cleaned_email FROM users GROUP BY cleaned_email ORDER BY id `"See full answer

    Backend Engineer
    Coding
    +3 more
  • +20

    "Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search. First, we should analyze the pattern of a regular number array without a single disrupter. Index: 0 1 2 3 4. 5 6. 7. 8. 9 Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6] notice the odd indexes are always referencing the second of the reoccurring numbers and t"

    Bamboo Y. - "Since the problem asks for a O(logN) solution, I have to assume that the numbers are already sorted, meaning the same number are adjacent to each other, the value of the numbers shouldn't matter, and they expect us to use Binary Search. First, we should analyze the pattern of a regular number array without a single disrupter. Index: 0 1 2 3 4. 5 6. 7. 8. 9 Array:[1, 1, 2, 2, 4, 4, 5, 5, 6, 6] notice the odd indexes are always referencing the second of the reoccurring numbers and t"See full answer

    Software Engineer
    Coding
  • "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"

    Aashka C. - "Sorted the array and stored the minimum difference in a variable and then traversed the array for the pairs having minimum difference"See full answer

    Software Engineer
    Coding
    +1 more
  • Oracle logoAsked at Oracle 
    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    +29

    "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
  • Video answer for 'How would you remove duplicates in a string?'
    +10

    " O(n) - characters in the string O(n) - stack def identify_adjacent(s: str, k: int) -> str: stack = [] n = len(s) for ch in s: if stack: topch, topcnt = stack[-1] if top_ch == ch: top_cnt += 1 stack[-1] = (ch, top_cnt) else: top_cnt = 1 stack.append((ch,1)) if top_cnt == k: stack.pop() else: stack.append"

    Rick E. - " O(n) - characters in the string O(n) - stack def identify_adjacent(s: str, k: int) -> str: stack = [] n = len(s) for ch in s: if stack: topch, topcnt = stack[-1] if top_ch == ch: top_cnt += 1 stack[-1] = (ch, top_cnt) else: top_cnt = 1 stack.append((ch,1)) if top_cnt == k: stack.pop() else: stack.append"See full answer

    Coding
    Data Structures & Algorithms
  • "2 Approaches: 1) The more intuitive approach is doing a multi-source BFS from all cats and storing the distance of closest cats. Then do a dfs/bfs from rat to bread. Time Complexity: O(mn + 4^L) where L is path length, worst case L could be mn Space Complexity: O(m*n) 2) The first approach should be fine for interviews. But if they ask to optimize it further, you can use Binary Search. Problems like "Finding max of min distance" or "Finding min of max" could be usually solved by BS. "

    Karan K. - "2 Approaches: 1) The more intuitive approach is doing a multi-source BFS from all cats and storing the distance of closest cats. Then do a dfs/bfs from rat to bread. Time Complexity: O(mn + 4^L) where L is path length, worst case L could be mn Space Complexity: O(m*n) 2) The first approach should be fine for interviews. But if they ask to optimize it further, you can use Binary Search. Problems like "Finding max of min distance" or "Finding min of max" could be usually solved by BS. "See full answer

    Software Engineer
    Coding
    +1 more
  • "This was a 60 minute assessment. The clock is ticking and you're being observed by a senior+ level engineer. Be ready to perform for an audience. The implementation for the system gets broken up into three parts: Implement creating accounts and depositing money into an account by ID Implement transferring money with validation to ensure the accounts for the transfer both exist and that the account money is being removed from has enough money in it to perform the transfer Implement find"

    devopsjesus - "This was a 60 minute assessment. The clock is ticking and you're being observed by a senior+ level engineer. Be ready to perform for an audience. The implementation for the system gets broken up into three parts: Implement creating accounts and depositing money into an account by ID Implement transferring money with validation to ensure the accounts for the transfer both exist and that the account money is being removed from has enough money in it to perform the transfer Implement find"See full answer

    Software Engineer
    Coding
    +1 more
Showing 1-20 of 374