Coding Interview Questions

Review this list of 363 coding interview questions and answers verified by hiring managers and candidates.
  • Coding
    Machine Learning
  • +13

    "The unique id is not clear in this question"

    Anonymous Possum - "The unique id is not clear in this question"See full answer

    Coding
    SQL
  • +6

    "I might be missing something but the solution, seems to be incorrect. ... , post_pairings AS ( SELECT ps.user_id, ps.postseqid AS failpostid, ps.postseqid + 1 AS nextpostid FROM post_seq AS ps WHERE ps.issuccessfulpost IS TRUE ) -- here ps.issuccessfulpost IS TRUE the condition should be FALSE -- in that way ps.postseqid is the actual failed post(failpostid) -- Additionally, at the end the join is assumming that the sequence id is going to match the post_id, wh"

    Jaime A. - "I might be missing something but the solution, seems to be incorrect. ... , post_pairings AS ( SELECT ps.user_id, ps.postseqid AS failpostid, ps.postseqid + 1 AS nextpostid FROM post_seq AS ps WHERE ps.issuccessfulpost IS TRUE ) -- here ps.issuccessfulpost IS TRUE the condition should be FALSE -- in that way ps.postseqid is the actual failed post(failpostid) -- Additionally, at the end the join is assumming that the sequence id is going to match the post_id, wh"See full answer

    Coding
    SQL
  • +4

    "-- Write your query here WITH high_value AS( SELECT user_id FROM user_sessions JOIN attribution ON usersessions.sessionid = attribution.session_id GROUP BY user_id HAVING SUM(purchase_value) > 100 ORDER BY SUM(purchase_value) DESC ) SELECT usersessions.userid, marketing_channel FROM user_sessions JOIN high_value ON usersessions.userid = highvalue.userid JOIN attribution ON usersessions.sessionid = attribution.session_id GROUP BY usersessions.userid H"

    Alina G. - "-- Write your query here WITH high_value AS( SELECT user_id FROM user_sessions JOIN attribution ON usersessions.sessionid = attribution.session_id GROUP BY user_id HAVING SUM(purchase_value) > 100 ORDER BY SUM(purchase_value) DESC ) SELECT usersessions.userid, marketing_channel FROM user_sessions JOIN high_value ON usersessions.userid = highvalue.userid JOIN attribution ON usersessions.sessionid = attribution.session_id GROUP BY usersessions.userid H"See full answer

    Coding
    SQL
  • Apple logoAsked at Apple 
    +9

    "I was able to answer this question and the follow-up questions as well"

    Anonymous Wasp - "I was able to answer this question and the follow-up questions as well"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 
    Software Engineer
    Coding
    +4 more
  • Microsoft logoAsked at Microsoft 

    "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
  • +14

    " from typing import Dict, List, Optional def max_profit(prices: Dict[str, int]) -> Optional[List[str]]: pass # your code goes here max = [None, 0] min = [None, float("inf")] for city, price in prices.items(): if price > max[1]: max[0], max[1] = city, price if price 0: return [min[0], max[0]] return None debug your code below prices = {'"

    Rick E. - " from typing import Dict, List, Optional def max_profit(prices: Dict[str, int]) -> Optional[List[str]]: pass # your code goes here max = [None, 0] min = [None, float("inf")] for city, price in prices.items(): if price > max[1]: max[0], max[1] = city, price if price 0: return [min[0], max[0]] return None debug your code below prices = {'"See full answer

    Coding
    Data Structures & Algorithms
  • +12

    "I'm pretty sure Exponent's answer is wrong. In the snippet below, they use "pl.name = 'Telephones' to attempt to filter down to the Telephone transactions, but they do this within a LEFT JOIN which means all product_lines rows are returned. > LEFT JOIN product_lines pl > ON p.productlineid = pl.id > AND pl.name = 'Telephones' Below is my solution. Also, I didn't see anywhere that said the "amount" column was in cents instead of dollars, but I still divided by 100 to be consistent with Exp"

    Bradley E. - "I'm pretty sure Exponent's answer is wrong. In the snippet below, they use "pl.name = 'Telephones' to attempt to filter down to the Telephone transactions, but they do this within a LEFT JOIN which means all product_lines rows are returned. > LEFT JOIN product_lines pl > ON p.productlineid = pl.id > AND pl.name = 'Telephones' Below is my solution. Also, I didn't see anywhere that said the "amount" column was in cents instead of dollars, but I still divided by 100 to be consistent with Exp"See full answer

    Coding
    SQL
  • +6

    "productssold = set(transactions['productid']) unsoldproducts = products.loc[~products['id'].isin(productssold)] return unsold_products[["id", "name", "stock"]] `"

    Laura U. - "productssold = set(transactions['productid']) unsoldproducts = products.loc[~products['id'].isin(productssold)] return unsold_products[["id", "name", "stock"]] `"See full answer

    Coding
    Data Analysis
  • Adobe logoAsked at Adobe 
    +1

    "const ops = { '+': (a, b) => a+b, '-': (a, b) => a-b, '/': (a, b) => a/b, '': (a, b) => ab, }; function calc(expr) { // Search for + or - for (let i=expr.length-1; i >= 0; i--) { const char = expr.charAt(i); if (['+', '-'].includes(char)) { return opschar), calc(expr.slice(i+1))); } } // Search for / or * for (let i=expr.length-1; i >= 0; i--) { const char = expr.charAt(i); if"

    Tiago R. - "const ops = { '+': (a, b) => a+b, '-': (a, b) => a-b, '/': (a, b) => a/b, '': (a, b) => ab, }; function calc(expr) { // Search for + or - for (let i=expr.length-1; i >= 0; i--) { const char = expr.charAt(i); if (['+', '-'].includes(char)) { return opschar), calc(expr.slice(i+1))); } } // Search for / or * for (let i=expr.length-1; i >= 0; i--) { const char = expr.charAt(i); if"See full answer

    Software Engineer
    Coding
    +3 more
  • Capital One logoAsked at Capital One 
    Software Engineer
    Coding
    +2 more
  • Adobe logoAsked at Adobe 
    +37

    "from typing import List def two_sum(nums: List[int], target: int) -> List[int]: prevMap = {} for i, n in enumerate(nums): diff = target - n if diff in prevMap: return [prevMap[diff], i] else: prevMap[n] = i return [] debug your code below print(two_sum([2, 7, 11, 15], 9)) `"

    Anonymous Roadrunner - "from typing import List def two_sum(nums: List[int], target: int) -> List[int]: prevMap = {} for i, n in enumerate(nums): diff = target - n if diff in prevMap: return [prevMap[diff], i] else: prevMap[n] = i return [] debug your code below print(two_sum([2, 7, 11, 15], 9)) `"See full answer

    Software Engineer
    Coding
    +5 more
  • +6

    " with youngsuccrate as( select strftime('%m', postdate) AS postmonth, round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as yascrate from post where userid in (select userid from post_user where age between 0 and 18) group by post_month ), nonyoungsucc_rate as( select strftime('%m', postdate) AS postmonth, round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as nonyasc_rate from post where user_id in (select"

    Bhavna S. - " with youngsuccrate as( select strftime('%m', postdate) AS postmonth, round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as yascrate from post where userid in (select userid from post_user where age between 0 and 18) group by post_month ), nonyoungsucc_rate as( select strftime('%m', postdate) AS postmonth, round(sum(issuccessfulpost)*1.0/count(issuccessfulpost),2)as nonyasc_rate from post where user_id in (select"See full answer

    Coding
    SQL
  • Waymo logoAsked at Waymo 
    +3

    " import pandas as pd def findaveragedistance(gps_data: pd.DataFrame) -> pd.DataFrame: #0. IMPORTANT: get the unordered pairs gpsdata['city1']=gpsdata[['origin','destination']].min(axis=1) gpsdata['city2']=gpsdata[['origin','destination']].max(axis=1) #1. get the mean distance by cities avgdistance=gpsdata.groupby(['city1','city2'], as_index=False)['distance'].mean().round(2) avgdistance.rename(columns={'distance':"averagedistance"}, inplace=True) "

    Sean L. - " import pandas as pd def findaveragedistance(gps_data: pd.DataFrame) -> pd.DataFrame: #0. IMPORTANT: get the unordered pairs gpsdata['city1']=gpsdata[['origin','destination']].min(axis=1) gpsdata['city2']=gpsdata[['origin','destination']].max(axis=1) #1. get the mean distance by cities avgdistance=gpsdata.groupby(['city1','city2'], as_index=False)['distance'].mean().round(2) avgdistance.rename(columns={'distance':"averagedistance"}, inplace=True) "See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • Amazon logoAsked at Amazon 
    Video answer for 'How do you split a machine learning dataset for training, evaluation, and testing?'

    "It depends on the size of the dataset. You want enough samples in both the testing, training and evaluation sets. If there is enough data, 70/20/10 is a good split"

    Jasmine Y. - "It depends on the size of the dataset. You want enough samples in both the testing, training and evaluation sets. If there is enough data, 70/20/10 is a good split"See full answer

    Coding
    Data Structures & Algorithms
  • "Yes, I need to compare the first half of the first string with the reverse order of the second half of the second string. Repeat this process to the first half of the second string and the second half of the first string."

    Anonymous Condor - "Yes, I need to compare the first half of the first string with the reverse order of the second half of the second string. Repeat this process to the first half of the second string and the second half of the first string."See full answer

    Machine Learning Engineer
    Coding
    +1 more
  • "Use an index, two pointers, and a set to keep track of elements that you've seen. pseudo code follows: for i, elem in enumerate(array): if elem in set return False if i > N: set.remove(array[i-N])"

    Michael B. - "Use an index, two pointers, and a set to keep track of elements that you've seen. pseudo code follows: for i, elem in enumerate(array): if elem in set return False if i > N: set.remove(array[i-N])"See full answer

    Machine Learning Engineer
    Coding
  • Adobe logoAsked at Adobe 
    Video answer for 'Generate Parentheses'
    +5

    "function generateParentheses(n) { if (n < 1) { return []; } if (n === 1) { return ["()"]; } const combinations = new Set(); let previousCombinations = generateParentheses(n-1); for (let prev of previousCombinations) { for (let i=0; i < prev.length; i++) { combinations.add(prev.slice(0, i+1) + "()" + prev.slice(i+1)); } } return [...combinations]; } `"

    Tiago R. - "function generateParentheses(n) { if (n < 1) { return []; } if (n === 1) { return ["()"]; } const combinations = new Set(); let previousCombinations = generateParentheses(n-1); for (let prev of previousCombinations) { for (let i=0; i < prev.length; i++) { combinations.add(prev.slice(0, i+1) + "()" + prev.slice(i+1)); } } return [...combinations]; } `"See full answer

    Software Engineer
    Coding
    +3 more
Showing 121-140 of 363