Software Engineer Coding Interview Questions

Review this list of 175 coding software engineer interview questions and answers verified by hiring managers and candidates.
  • Amazon logoAsked at Amazon 

    "class Node: def init(self, value): self.value = value self.children = [] def inorder_traversal(root): if not root: return [] result = [] n = len(root.children) for i in range(n): result.extend(inorder_traversal(root.children[i])) if i == n // 2: result.append(root.value) if n == 0: result.append(root.value) return result Example usage: root = Node(1) child1 = Node(2) chil"

    Teddy Y. - "class Node: def init(self, value): self.value = value self.children = [] def inorder_traversal(root): if not root: return [] result = [] n = len(root.children) for i in range(n): result.extend(inorder_traversal(root.children[i])) if i == n // 2: result.append(root.value) if n == 0: result.append(root.value) return result Example usage: root = Node(1) child1 = Node(2) chil"See full answer

    Software Engineer
    Coding
    +1 more
  • +2

    "Traverse the array of points while computing the distance and pushing it to the heap. Then traverse again the heap and pop the k closest. Time O(nlogn) Space O(n)"

    Dadja Z. - "Traverse the array of points while computing the distance and pushing it to the heap. Then traverse again the heap and pop the k closest. Time O(nlogn) Space O(n)"See full answer

    Software Engineer
    Coding
    +2 more
  • "MOD = 10**9 + 7 def max_stability(reliability, availability): max_stability = 1 for r, a in zip(reliability, availability): Compute stability of the current server stability = r * a if stability != 0: Multiply into max_stability and take modulo maxstability = (maxstability * stability) % MOD return max_stability reliability = [1, 2, 2] availability = [1, 1, 3] print(max_stability(reliability, availability)) # Output the result mo"

    K.nithish K. - "MOD = 10**9 + 7 def max_stability(reliability, availability): max_stability = 1 for r, a in zip(reliability, availability): Compute stability of the current server stability = r * a if stability != 0: Multiply into max_stability and take modulo maxstability = (maxstability * stability) % MOD return max_stability reliability = [1, 2, 2] availability = [1, 1, 3] print(max_stability(reliability, availability)) # Output the result mo"See full answer

    Software Engineer
    Coding
  • "def mostefficientseqscore(parentheses, efficiencyratings): mes = [] for i in range(len(parentheses)): mes.append((parentheses[i], max(efficiency_ratings[i])) return sum([m[1] for m in mes]) `"

    Nathan C. - "def mostefficientseqscore(parentheses, efficiencyratings): mes = [] for i in range(len(parentheses)): mes.append((parentheses[i], max(efficiency_ratings[i])) return sum([m[1] for m in mes]) `"See full answer

    Software Engineer
    Coding
  • Apple logoAsked at Apple 
    +9

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

  • Adobe logoAsked at Adobe 
    Video answer for 'Explain how to find a target sum in an array.'
    +2

    "A recursive backtracking solution in python. def changeSigns(nums: List[int], S: int) -> int: res = [] n = len(nums) def backtrack(index, curr, arr): if curr == S and len(arr) == n: res.append(arr[:]) return if index >= len(nums): return for i in range(index, n): add +ve number arr.append(nums[i]) backtrack(i+1, curr + nums[i], arr) arr.pop() "

    Yugaank K. - "A recursive backtracking solution in python. def changeSigns(nums: List[int], S: int) -> int: res = [] n = len(nums) def backtrack(index, curr, arr): if curr == S and len(arr) == n: res.append(arr[:]) return if index >= len(nums): return for i in range(index, n): add +ve number arr.append(nums[i]) backtrack(i+1, curr + nums[i], arr) arr.pop() "See full answer

    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    +20

    "#inplace reversal without inbuilt functions def reverseString(s): chars = list(s) l, r = 0, len(s)-1 while l < r: chars[l],chars[r] = chars[r],chars[l] l += 1 r -= 1 reversed = "".join(chars) return reversed "

    Anonymous Possum - "#inplace reversal without inbuilt functions def reverseString(s): chars = list(s) l, r = 0, len(s)-1 while l < r: chars[l],chars[r] = chars[r],chars[l] l += 1 r -= 1 reversed = "".join(chars) return reversed "See full answer

    Software Engineer
    Coding
    +4 more
  • "Abstract class A class that can have Abstract methods - without implementations and Concerete Methods i.e with implementation. Can have private, protected and public access modifiers. Supports Single inheritance i.e a class can extend only 1 abstract class Can have constructors Mainly used when sharing common behaviors Interface Class A collection of abstract methods ( can have static and default methods also - onwards of java 8) Public, static, final are the access"

    Sue G. - "Abstract class A class that can have Abstract methods - without implementations and Concerete Methods i.e with implementation. Can have private, protected and public access modifiers. Supports Single inheritance i.e a class can extend only 1 abstract class Can have constructors Mainly used when sharing common behaviors Interface Class A collection of abstract methods ( can have static and default methods also - onwards of java 8) Public, static, final are the access"See full answer

    Software Engineer
    Coding
    +2 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Video answer for 'Merge Intervals'
    +33

    "const mergeIntervals = (intervals) => { const compare = (a, b) => { if(a[0] b[0]) return 1 else if(a[0] === b[0]) { return a[1] - b[1] } } let current = [] const result = [] const sorted = intervals.sort(compare) for(let i = 0; i = b[0]) current[1] = b[1] els"

    Kofi N. - "const mergeIntervals = (intervals) => { const compare = (a, b) => { if(a[0] b[0]) return 1 else if(a[0] === b[0]) { return a[1] - b[1] } } let current = [] const result = [] const sorted = intervals.sort(compare) for(let i = 0; i = b[0]) current[1] = b[1] els"See full answer

    Software Engineer
    Coding
    +6 more
  • Microsoft logoAsked at Microsoft 

    "Let me try to explain it with simple life analogy You're cooking dinner in the kitchen. Multithreading is when you've got a bunch of friends helping out. Each friend does a different job—like one chops veggies while another stirs a sauce. Everyone focuses on their task, and together, you all make the meal faster. In a computer, it's like different jobs happening all at once, making stuff happen quicker, just like having lots of friends helping makes dinner ready faster."

    Praveen D. - "Let me try to explain it with simple life analogy You're cooking dinner in the kitchen. Multithreading is when you've got a bunch of friends helping out. Each friend does a different job—like one chops veggies while another stirs a sauce. Everyone focuses on their task, and together, you all make the meal faster. In a computer, it's like different jobs happening all at once, making stuff happen quicker, just like having lots of friends helping makes dinner ready faster."See full answer

    Software Engineer
    Coding
    +1 more
  • "python: def justifywords(wordslist, width): result = [] currlinechar_count = 0 curr_words = [] for word in words_list: if curr_words: space_needed = len(word) + 1 # Space needed for the word and a preceding space else: space_needed = len(word) if currlinecharcount + spaceneeded > width: result.append(' '.join(curr_words)) curr_words = [word] currlinechar_count = len("

    Anonymous Unicorn - "python: def justifywords(wordslist, width): result = [] currlinechar_count = 0 curr_words = [] for word in words_list: if curr_words: space_needed = len(word) + 1 # Space needed for the word and a preceding space else: space_needed = len(word) if currlinecharcount + spaceneeded > width: result.append(' '.join(curr_words)) curr_words = [word] currlinechar_count = len("See full answer

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

    "public class CircularBuffer { private T[] buffer; private int head; private int tail; private int size; private final int capacity; public CircularBuffer(int capacity) { this.capacity = capacity; this.buffer = (T[]) new Object[capacity]; this.head = 0; this.tail = 0; this.size = 0; } public void enqueue(T item) { if (isFull()) { throw new IllegalStateException("Buffer is full"); } buf"

    Vidhyadhar V. - "public class CircularBuffer { private T[] buffer; private int head; private int tail; private int size; private final int capacity; public CircularBuffer(int capacity) { this.capacity = capacity; this.buffer = (T[]) new Object[capacity]; this.head = 0; this.tail = 0; this.size = 0; } public void enqueue(T item) { if (isFull()) { throw new IllegalStateException("Buffer is full"); } buf"See full answer

    Software Engineer
    Coding
    +1 more
  • +1

    "Approach 1: Use sorting and return the kth largest element from the sorted list. Time complexity: O(nlogn) Approach 2: Use max heap and then select the kth largest element. time complexity: O(n+logn) Approach 3: Quickselect. Time complexity O(n) I explained my interviewer the 3 approaches. He told me to solve in a naive manner. Used Approach 1 had some time left so coded approach 3 also The average time complexity of Quickselect is O(n), making it very efficient for its purpose. However, in"

    GalacticInterviewer - "Approach 1: Use sorting and return the kth largest element from the sorted list. Time complexity: O(nlogn) Approach 2: Use max heap and then select the kth largest element. time complexity: O(n+logn) Approach 3: Quickselect. Time complexity O(n) I explained my interviewer the 3 approaches. He told me to solve in a naive manner. Used Approach 1 had some time left so coded approach 3 also The average time complexity of Quickselect is O(n), making it very efficient for its purpose. However, in"See full answer

    Software Engineer
    Coding
    +1 more
  • "def encode(root): if not root: return [] def dfs(node): if not node: return res.append(node.val) res.append(len(node,children)) for child_node in node.children: dfs(child_node) res = [] dfs(root) return res def decode(arr): if not arr: return None n = len(arr) i = 0 def dfs(val, children_count): if children_count == 0: return Node(val) cur_node = Node(val) cur_node.children = [] for j in range(children_count): nonlocal i i += 2 cur_node.children.append(dfs(arr[i], arr[i"

    Ying T. - "def encode(root): if not root: return [] def dfs(node): if not node: return res.append(node.val) res.append(len(node,children)) for child_node in node.children: dfs(child_node) res = [] dfs(root) return res def decode(arr): if not arr: return None n = len(arr) i = 0 def dfs(val, children_count): if children_count == 0: return Node(val) cur_node = Node(val) cur_node.children = [] for j in range(children_count): nonlocal i i += 2 cur_node.children.append(dfs(arr[i], arr[i"See full answer

    Software Engineer
    Coding
  • Amazon logoAsked at Amazon 
    +4

    "this assumes that the dependency among courses is in a growing order: 0 -> 1 -> 2 -> ... if not, then the code will not work"

    Gabriele G. - "this assumes that the dependency among courses is in a growing order: 0 -> 1 -> 2 -> ... if not, then the code will not work"See full answer

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

    "function isValid(s) { const stack = []; for (let i=0; i < s.length; i++) { const char = s.charAt(i); if (['(', '{', '['].includes(char)) { stack.push(char); } else { const top = stack.pop(); if ((char === ')' && top !== '(') || (char === '}' && top !== '{') || (char === ']' && top !== '[')) { return false; } } } return stack.length === 0"

    Tiago R. - "function isValid(s) { const stack = []; for (let i=0; i < s.length; i++) { const char = s.charAt(i); if (['(', '{', '['].includes(char)) { stack.push(char); } else { const top = stack.pop(); if ((char === ')' && top !== '(') || (char === '}' && top !== '{') || (char === ']' && top !== '[')) { return false; } } } return stack.length === 0"See full answer

    Software Engineer
    Coding
    +4 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Find the median of two sorted arrays.'
    Software Engineer
    Coding
    +4 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
  • Amazon logoAsked at Amazon 

    "input_logs = [ f"{senderid} {receiverid} {transaction_count}" "1 2 2", "3 2 42", "2 2 22", "1 1 12", "2 1 1", "2 5 4", "4 2 15" ] input_threshold = 20 exptected_output = [ list of user_ids that made more than 20 transactions sorted by number of transactions in descending order "3", # 42 transactions "2", # 27 transactions (22 + 1 + 4) #"4", # 15 transactions #"1" # 14 transactions (2 + 12 + 1) ] def gettopapi_users(logs, thres"

    Anonymous Unicorn - "input_logs = [ f"{senderid} {receiverid} {transaction_count}" "1 2 2", "3 2 42", "2 2 22", "1 1 12", "2 1 1", "2 5 4", "4 2 15" ] input_threshold = 20 exptected_output = [ list of user_ids that made more than 20 transactions sorted by number of transactions in descending order "3", # 42 transactions "2", # 27 transactions (22 + 1 + 4) #"4", # 15 transactions #"1" # 14 transactions (2 + 12 + 1) ] def gettopapi_users(logs, thres"See full answer

    Software Engineer
    Coding
    +1 more
  • "naive solution: def countprefixpairs(words): n = len(words) count = 0 for i in range(n): for j in range(i + 1, n): if words[i].startswith(words[j]) or words[j].startswith(words[i]): count += 1 return count using tries for when the list of words is very long: from collections import Counter class TrieNode: def init(self): self.children = {} self.count = 0 # To count the number of words ending at this node"

    Anonymous Unicorn - "naive solution: def countprefixpairs(words): n = len(words) count = 0 for i in range(n): for j in range(i + 1, n): if words[i].startswith(words[j]) or words[j].startswith(words[i]): count += 1 return count using tries for when the list of words is very long: from collections import Counter class TrieNode: def init(self): self.children = {} self.count = 0 # To count the number of words ending at this node"See full answer

    Software Engineer
    Coding
Showing 21-40 of 175