Coding Interview Questions

Review this list of 344 coding interview questions and answers verified by hiring managers and candidates.
  • "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
  • +22

    "SELECT d.name as departmentname,e.id as employeeid,e.firstname,e.lastname,MAX(e.salary) as salary FROM employees e LEFT JOIN departments d ON e.department_id=d.id GROUP BY department_name ORDER BY department_name;"

    Anisha S. - "SELECT d.name as departmentname,e.id as employeeid,e.firstname,e.lastname,MAX(e.salary) as salary FROM employees e LEFT JOIN departments d ON e.department_id=d.id GROUP BY department_name ORDER BY department_name;"See full answer

    Data Scientist
    Coding
    +1 more
  • Atlassian logoAsked at Atlassian 
    Video answer for 'How would you store a list of numbers as a single number?'
    +7

    "First thing the interviewee did wrong is not asking clarifying questions. This is the most vague problem I have every heard, and the interviewee just made assumptions and started programming."

    Nicholas S. - "First thing the interviewee did wrong is not asking clarifying questions. This is the most vague problem I have every heard, and the interviewee just made assumptions and started programming."See full answer

    Engineering Manager
    Coding
    +2 more
  • "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
  • "solving to find a cycle in directed graph"

    XponentShift32 - "solving to find a cycle in directed graph"See full answer

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

  • 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
  • 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
  • +16

    "SELECT u.user_id, u.user_name, u.email, ROUND(AVG(CASE WHEN b.status = 'Unmatched' THEN 1.0 ELSE 0 END), 2) AS avgunmatchedbookings FROM users u LEFT JOIN bookings b ON u.userid = b.userid GROUP BY u.user_id, u.user_name, u.email; `"

    Akshay D. - "SELECT u.user_id, u.user_name, u.email, ROUND(AVG(CASE WHEN b.status = 'Unmatched' THEN 1.0 ELSE 0 END), 2) AS avgunmatchedbookings FROM users u LEFT JOIN bookings b ON u.userid = b.userid GROUP BY u.user_id, u.user_name, u.email; `"See full answer

    Data Scientist
    Coding
    +1 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
  • 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
  • +9

    "Required output in the solution not the one requested from the question. only customerid, firstname, last_name and years were required. Please this needs to be very clear. Otherwise my answer is with totalorderyear as ( SELECT o.customer_id, c.first_name, c.last_name, EXTRACT(YEAR FROM o.orderdate) AS orderyear, COUNT(o.orderid) AS totalorders FROM orders o LEFT JOIN customers c ON c.customerid = o.customerid GROUP BY o.customerid, c.firstname, c.last"

    Gloriose H. - "Required output in the solution not the one requested from the question. only customerid, firstname, last_name and years were required. Please this needs to be very clear. Otherwise my answer is with totalorderyear as ( SELECT o.customer_id, c.first_name, c.last_name, EXTRACT(YEAR FROM o.orderdate) AS orderyear, COUNT(o.orderid) AS totalorders FROM orders o LEFT JOIN customers c ON c.customerid = o.customerid GROUP BY o.customerid, c.firstname, c.last"See full answer

    Data Scientist
    Coding
    +1 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
  • "I used array to append. np.array does not have append and every np.vstack recreates object again. import numpy as np class Centroid: def init(self, location, vectors): self.location = location # (D,) self.vectors = vectors # (N_i, D) class KMeans: def init(self, n_features, k): self.nfeatures = nfeatures self.centroids = [ Centroid( location=np.random.randn(n_features), vectors=[] # I"

    Dinar M. - "I used array to append. np.array does not have append and every np.vstack recreates object again. import numpy as np class Centroid: def init(self, location, vectors): self.location = location # (D,) self.vectors = vectors # (N_i, D) class KMeans: def init(self, n_features, k): self.nfeatures = nfeatures self.centroids = [ Centroid( location=np.random.randn(n_features), vectors=[] # I"See full answer

    Coding
    Machine Learning
  • 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
  • Video answer for 'E-commerce (1 of 5)'
    +14

    "SELECT SUM(orderquantity) AS totalunitsorderedyesterday FROM orders WHERE order_date = DATE('now', '-1 DAY') `"

    Akshay D. - "SELECT SUM(orderquantity) AS totalunitsorderedyesterday FROM orders WHERE order_date = DATE('now', '-1 DAY') `"See full answer

    Data Scientist
    Coding
    +1 more
  • +1

    "You can ask some clarifying questions like 1) Ask if the list is already sorted or not 2) is zero included in the list ? 3) Natural numbers are usually positive numbers ( clarify they are non negatives) Solution : 1) If sorted use two pointers and sort them in O(N) 2) if not sorted , -ve / only +ve numbers in the list doesn't matter - the easiest solution is Use a priority queue and push the number and its square in each iteration Finally return the list returned by the priority Queue. N"

    Bless M. - "You can ask some clarifying questions like 1) Ask if the list is already sorted or not 2) is zero included in the list ? 3) Natural numbers are usually positive numbers ( clarify they are non negatives) Solution : 1) If sorted use two pointers and sort them in O(N) 2) if not sorted , -ve / only +ve numbers in the list doesn't matter - the easiest solution is Use a priority queue and push the number and its square in each iteration Finally return the list returned by the priority Queue. N"See full answer

    Machine Learning 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
  • "It's a 2Sum question with duplicate array elements."

    Anzhe M. - "It's a 2Sum question with duplicate array elements."See full answer

    Data Engineer
    Coding
    +1 more
Showing 41-60 of 344