Software Engineer Coding Interview Questions

Review this list of 175 coding software engineer interview questions and answers verified by hiring managers and candidates.
  • Adobe logoAsked at Adobe 
    Video answer for 'Move all zeros to the end of an array.'
    +39

    "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
  • Adobe logoAsked at Adobe 
    +6

    " function climbStairs(n) { // 4 iterations of Dynamic Programming solutions: // Step 1: Recursive: // if (n <= 2) return n // return climbStairs(n-1) + climbStairs(n-2) // Step 2: Top-down Memoization // const memo = {0:0, 1:1, 2:2} // function f(x) { // if (x in memo) return memo[x] // memo[x] = f(x-1) + f(x-2) // return memo[x] // } // return f(n) // Step 3: Bottom-up Tabulation // const tab = [0,1,2] // f"

    Matthew K. - " function climbStairs(n) { // 4 iterations of Dynamic Programming solutions: // Step 1: Recursive: // if (n <= 2) return n // return climbStairs(n-1) + climbStairs(n-2) // Step 2: Top-down Memoization // const memo = {0:0, 1:1, 2:2} // function f(x) { // if (x in memo) return memo[x] // memo[x] = f(x-1) + f(x-2) // return memo[x] // } // return f(n) // Step 3: Bottom-up Tabulation // const tab = [0,1,2] // f"See full answer

    Software Engineer
    Coding
    +3 more
  • +7

    "Without using a recursive approach, one can perform a post-order traversal by removing the parent nodes from the stack only if children were visited: def diameterOfTree(root): if root is None: return 0 diameter = 0 stack = deque([[root, False]]) # (node, visited) node_heights = {} while stack: curr_node, visited = stack[-1] if visited: heightleft = nodeheights.get(curr_node.left, 0) heightright = nodehe"

    Gabriele G. - "Without using a recursive approach, one can perform a post-order traversal by removing the parent nodes from the stack only if children were visited: def diameterOfTree(root): if root is None: return 0 diameter = 0 stack = deque([[root, False]]) # (node, visited) node_heights = {} while stack: curr_node, visited = stack[-1] if visited: heightleft = nodeheights.get(curr_node.left, 0) heightright = nodehe"See full answer

    Software Engineer
    Coding
    +1 more
  • Google logoAsked at Google 
    Video answer for 'Write functions to serialize and deserialize a list of strings.'
    +4

    "Maybe we can use this solution: 1, connect all the strings together, and add an integer value ahead each string. 2, use Huffmans algorithm to encode the step 1 result, to make the result size smaller. 3, return the root of Huffmans tree. This solution man be slower than the common serialize method, but it can save a lot of memory, I think, at lease doing serialize is mainly for tranfering data or storing data."

    Jordan Z. - "Maybe we can use this solution: 1, connect all the strings together, and add an integer value ahead each string. 2, use Huffmans algorithm to encode the step 1 result, to make the result size smaller. 3, return the root of Huffmans tree. This solution man be slower than the common serialize method, but it can save a lot of memory, I think, at lease doing serialize is mainly for tranfering data or storing data."See full answer

    Software Engineer
    Coding
    +1 more
  • Amazon logoAsked at Amazon 

    "Was the statement very similar to the leetcode or was it changed and only the main idea remained?"

    Anonymous Wombat - "Was the statement very similar to the leetcode or was it changed and only the main idea remained?"See full answer

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

  • Adobe logoAsked at Adobe 
    Video answer for 'Given the root of a binary tree of integers, return the maximum path sum.'

    "\# Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def maxPathSum(self, root: TreeNode) -> int: self.max_sum = float('-inf')"

    Jerry O. - "\# Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def maxPathSum(self, root: TreeNode) -> int: self.max_sum = float('-inf')"See full answer

    Software Engineer
    Coding
    +4 more
  • Amazon logoAsked at Amazon 

    "Count items between indices within compartments compartments are delineated by by: '|' items are identified by: '*' input_inventory = "*||||" inputstartidxs = [1, 4, 6] inputendidxs = [9, 5, 8] expected_output = [3, 0, 1] Explanation: "*||||" 0123456789... indices ++ + # within compartments ^ start_idx = 1 ^ end_idx = 9 -- - # within idxs but not within compartments "*||||" 0123456789... indices "

    Anonymous Unicorn - "Count items between indices within compartments compartments are delineated by by: '|' items are identified by: '*' input_inventory = "*||||" inputstartidxs = [1, 4, 6] inputendidxs = [9, 5, 8] expected_output = [3, 0, 1] Explanation: "*||||" 0123456789... indices ++ + # within compartments ^ start_idx = 1 ^ end_idx = 9 -- - # within idxs but not within compartments "*||||" 0123456789... indices "See full answer

    Software Engineer
    Coding
    +1 more
  • "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line. Example: S = "abracadabra sample" K = 11 Output: abracadabra sample Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"

    B. T. - "You are given a string S and a number K as input, and your task is to print S to console output considering that, at most, you can print K characters per line. Example: S = "abracadabra sample" K = 11 Output: abracadabra sample Note that this problem requires the interviewee gather extra requirements from the interviewer (e.g. do we care about multiple white spaces? what if the length of a word is greater than K, ...)"See full answer

    Software Engineer
    Coding
    +1 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +8

    "public static Integer[] findLargest(int[] input, int m) { if(input==null || input.length==0) return null; PriorityQueue minHeap=new PriorityQueue(); for(int i:input) { if(minHeap.size()(int)top){ minHeap.poll(); minHeap.add(i); } } } Integer[] res=minHeap.toArray(new Integer[0]); Arrays.sort(res); return res; }"

    Divya R. - "public static Integer[] findLargest(int[] input, int m) { if(input==null || input.length==0) return null; PriorityQueue minHeap=new PriorityQueue(); for(int i:input) { if(minHeap.size()(int)top){ minHeap.poll(); minHeap.add(i); } } } Integer[] res=minHeap.toArray(new Integer[0]); Arrays.sort(res); return res; }"See full answer

    Software Engineer
    Coding
    +2 more
  • Amazon logoAsked at Amazon 
    Video answer for 'Implement k-means clustering.'

    "i dont know"

    Dinesh K. - "i dont know"See full answer

    Software Engineer
    Coding
    +5 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Product of Array Except Self'
    +38

    "Java import java.util.*; public class Solution { public static int[] productExceptSelf(int[] nums) { int n = nums.length; int[] result = new int[n]; // Step 1: Calculate left products result[0] = 1; for (int i = 1; i = 0; i--) { resul"

    Vignesh g 2. - "Java import java.util.*; public class Solution { public static int[] productExceptSelf(int[] nums) { int n = nums.length; int[] result = new int[n]; // Step 1: Calculate left products result[0] = 1; for (int i = 1; i = 0; i--) { resul"See full answer

    Software Engineer
    Coding
    +3 more
  • Software Engineer
    Coding
    +4 more
  • Adobe logoAsked at Adobe 
    Software Engineer
    Coding
    +4 more
  • Capital One logoAsked at Capital One 
    Software Engineer
    Coding
    +2 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Given an nxn grid of 1s and 0s, return the number of islands in the input.'
    +9

    " from typing import List def getnumberof_islands(binaryMatrix: List[List[int]]) -> int: if not binaryMatrix: return 0 rows = len(binaryMatrix) cols = len(binaryMatrix[0]) islands = 0 for r in range(rows): for c in range(cols): if binaryMatrixr == 1: islands += 1 dfs(binaryMatrix, r, c) return islands def dfs(grid, r, c): if ( r = len(grid) "

    Rick E. - " from typing import List def getnumberof_islands(binaryMatrix: List[List[int]]) -> int: if not binaryMatrix: return 0 rows = len(binaryMatrix) cols = len(binaryMatrix[0]) islands = 0 for r in range(rows): for c in range(cols): if binaryMatrixr == 1: islands += 1 dfs(binaryMatrix, r, c) return islands def dfs(grid, r, c): if ( r = len(grid) "See full answer

    Software Engineer
    Coding
    +4 more
  • Adobe logoAsked at Adobe 
    +7

    "function findPrimes(n) { if (n < 2) return []; const primes = []; for (let i=2; i <= n; i++) { const half = Math.floor(i/2); let isPrime = true; for (let prime of primes) { if (i % prime === 0) { isPrime = false; break; } } if (isPrime) { primes.push(i); } } return primes; } `"

    Tiago R. - "function findPrimes(n) { if (n < 2) return []; const primes = []; for (let i=2; i <= n; i++) { const half = Math.floor(i/2); let isPrime = true; for (let prime of primes) { if (i % prime === 0) { isPrime = false; break; } } if (isPrime) { primes.push(i); } } return primes; } `"See full answer

    Software Engineer
    Coding
    +4 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Find a triplet in an array with a given sum.'
    +5

    "from typing import List def three_sum(nums: List[int]) -> List[List[int]]: nums.sort() triplets = set() for i in range(len(nums) - 2): firstNum = nums[i] l = i + 1 r = len(nums) - 1 while l 0: r -= 1 elif potentialSum < 0: l += 1 "

    Anonymous Roadrunner - "from typing import List def three_sum(nums: List[int]) -> List[List[int]]: nums.sort() triplets = set() for i in range(len(nums) - 2): firstNum = nums[i] l = i + 1 r = len(nums) - 1 while l 0: r -= 1 elif potentialSum < 0: l += 1 "See full answer

    Software Engineer
    Coding
    +3 more
  • "Let’s say the matrix is m x n (i.e., m rows and n columns). Start from the top-right corner of the matrix. Move left if you see a 1. Move down if you see a 0. Keep track of the row index where you last saw the leftmost 1 — that row has the most 1s. public class MaxOnesRow { public static int rowWithMostOnes(int matrix) { int rows = matrix.length; int cols = matrix[0].length; int maxRowIndex = -1; int j = cols - 1; /"

    Khushbu R. - "Let’s say the matrix is m x n (i.e., m rows and n columns). Start from the top-right corner of the matrix. Move left if you see a 1. Move down if you see a 0. Keep track of the row index where you last saw the leftmost 1 — that row has the most 1s. public class MaxOnesRow { public static int rowWithMostOnes(int matrix) { int rows = matrix.length; int cols = matrix[0].length; int maxRowIndex = -1; int j = cols - 1; /"See full answer

    Software Engineer
    Coding
    +1 more
  • +9

    "from typing import List def maxprofitgreedy(stock_prices: List[int]) -> int: l=0 # buying r=1 # selling max_profit=0 while rstock_prices[l]: profit=stockprices[r]-stockprices[l] maxprofit=max(maxprofit,profit) else: l=r r+=1 return max_profit debug your code below print(maxprofitgreedy([7, 1, 5, 3, 6, 4])) `"

    Prajwal M. - "from typing import List def maxprofitgreedy(stock_prices: List[int]) -> int: l=0 # buying r=1 # selling max_profit=0 while rstock_prices[l]: profit=stockprices[r]-stockprices[l] maxprofit=max(maxprofit,profit) else: l=r r+=1 return max_profit debug your code below print(maxprofitgreedy([7, 1, 5, 3, 6, 4])) `"See full answer

    Software Engineer
    Coding
    +4 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    +1

    "my answer: void* memcpy(void* dest, const void* src, size_t n) { unsigned char* uDest = static_cast(dest); const unsigned char* ucSrc = static_cast(src); for(size_t i= 0; i(dest); const unsigned c"

    Srihitha J. - "my answer: void* memcpy(void* dest, const void* src, size_t n) { unsigned char* uDest = static_cast(dest); const unsigned char* ucSrc = static_cast(src); for(size_t i= 0; i(dest); const unsigned c"See full answer

    Software Engineer
    Coding
    +1 more
Showing 41-60 of 175