Coding Interview Questions

Review this list of 363 coding interview questions and answers verified by hiring managers and candidates.
  • LinkedIn logoAsked at LinkedIn 
    Software Engineer
    Coding
    +1 more
  • +4

    "function getDifferentNumberImmutable(arr) { const exists = new Array(arr.length).fill(false); for (let item of arr) { exists[item] = true; } for (let i=0; i < exists.length; i++) { if (!exists[i]) { return i; } } return arr.length; } function getDifferentNumber(arr) { let i=0; while (i < arr.length) { while (arr[i] < arr.length && arr[i] !== i) { // switch (arr[i] and arr[arr[i]]) const j = arr[i]; const temp = arr[j]; arr[j]"

    Tiago R. - "function getDifferentNumberImmutable(arr) { const exists = new Array(arr.length).fill(false); for (let item of arr) { exists[item] = true; } for (let i=0; i < exists.length; i++) { if (!exists[i]) { return i; } } return arr.length; } function getDifferentNumber(arr) { let i=0; while (i < arr.length) { while (arr[i] < arr.length && arr[i] !== i) { // switch (arr[i] and arr[arr[i]]) const j = arr[i]; const temp = arr[j]; arr[j]"See full answer

    Coding
    Data Structures & Algorithms
  • +3

    "def flatten_dictionary(dictionary): \# return a flattened dictionary - int/string/another dictionary values \# if the key is empty, exclude from the output \# concat using a "." btwn them \# add to res which is { "key.a.b.etc": "value" } \# iterate through the key value pairs \# while there is a key value pair in the value \# continue going through that, until the value is an int/string flatDic = {} flatDicHelper("", dictionary, flatDic) print(flatDic) return flatDic def flatDicHelper(initialKey"

    Anonymous Owl - "def flatten_dictionary(dictionary): \# return a flattened dictionary - int/string/another dictionary values \# if the key is empty, exclude from the output \# concat using a "." btwn them \# add to res which is { "key.a.b.etc": "value" } \# iterate through the key value pairs \# while there is a key value pair in the value \# continue going through that, until the value is an int/string flatDic = {} flatDicHelper("", dictionary, flatDic) print(flatDic) return flatDic def flatDicHelper(initialKey"See full answer

    Coding
    Data Structures & Algorithms
  • Robinhood logoAsked at Robinhood 

    "Assuming that trades will have information like trade_type buy or sell trade_price with these tuples, one can iterate over each trade while maintaining a stack which maintains all the open buy trades. If we encounter a sell trade then we pop one element make it a buy/sell pair and calculate the profit/loss for that pair. Moreover, keep adding pair-wise profit/loss to calculate overall profit as we continue iterating over trades. At the end print pairs and their profit/loss along with"

    Parth S. - "Assuming that trades will have information like trade_type buy or sell trade_price with these tuples, one can iterate over each trade while maintaining a stack which maintains all the open buy trades. If we encounter a sell trade then we pop one element make it a buy/sell pair and calculate the profit/loss for that pair. Moreover, keep adding pair-wise profit/loss to calculate overall profit as we continue iterating over trades. At the end print pairs and their profit/loss along with"See full answer

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

  • +1

    "WITH CTE AS ( SELECT *, ROWNUMBER()OVER(PARTITION BY utxoid ORDER BY transactionid) AS trxrk FROM transactions JOIN transaction_inputs USING (transaction_id) JOIN utxo USING (utxo_id) ) SELECT transaction_id AS InvalidTransactionId FROM CTE WHERE sender!=address OR trx_rk > 1 `"

    E L. - "WITH CTE AS ( SELECT *, ROWNUMBER()OVER(PARTITION BY utxoid ORDER BY transactionid) AS trxrk FROM transactions JOIN transaction_inputs USING (transaction_id) JOIN utxo USING (utxo_id) ) SELECT transaction_id AS InvalidTransactionId FROM CTE WHERE sender!=address OR trx_rk > 1 `"See full answer

    Coding
    SQL
  • Apple logoAsked at Apple 

    "Sorting is a technique to arrange data in either increasing order or decreasing order, and, the function that implements this functionality is called sort function"

    Farhan -. - "Sorting is a technique to arrange data in either increasing order or decreasing order, and, the function that implements this functionality is called sort function"See full answer

    Software Engineer
    Coding
    +1 more
  • Adobe logoAsked at Adobe 

    "static boolean sudokuSolve(char board) { return sudokuSolve(board, 0, 0); } static boolean sudokuSolve(char board, int r, int c) { if(c>=board[0].length) { r=r+1; c=0; } if(r>=board.length) return true; if(boardr=='.') { for(int num=1; num<=9; num++) { boardr=(char)('0' + num); if(isValidPosition(board, r, c)) { if(sudokuSolve(board, r, c+1)) return true; } boardr='.'; } } else { return sudokuSolve(board, r, c+1); } return false; } static boolean isValidPosition(char b"

    Divya R. - "static boolean sudokuSolve(char board) { return sudokuSolve(board, 0, 0); } static boolean sudokuSolve(char board, int r, int c) { if(c>=board[0].length) { r=r+1; c=0; } if(r>=board.length) return true; if(boardr=='.') { for(int num=1; num<=9; num++) { boardr=(char)('0' + num); if(isValidPosition(board, r, c)) { if(sudokuSolve(board, r, c+1)) return true; } boardr='.'; } } else { return sudokuSolve(board, r, c+1); } return false; } static boolean isValidPosition(char b"See full answer

    Software Engineer
    Coding
    +4 more
  • +4

    "Using a DFS approach, computing all the distances from typing import List from collections import deque def shortestCellPath(grid: List[List[int]], sr: int, sc: int, tr: int, tc: int) -> int: if sr == tr and sc == tc: return 0 nRows = len(grid) nCols = len(grid[0]) distances = [] stack = deque([(sr, sc, 0)]) visitedSet = set() while stack: nodeR, nodeC, nodeDist = stack.pop() if gridnodeR == 0 or (nodeR, nodeC) in visited"

    Gabriele G. - "Using a DFS approach, computing all the distances from typing import List from collections import deque def shortestCellPath(grid: List[List[int]], sr: int, sc: int, tr: int, tc: int) -> int: if sr == tr and sc == tc: return 0 nRows = len(grid) nCols = len(grid[0]) distances = [] stack = deque([(sr, sc, 0)]) visitedSet = set() while stack: nodeR, nodeC, nodeDist = stack.pop() if gridnodeR == 0 or (nodeR, nodeC) in visited"See full answer

    Coding
    Data Structures & Algorithms
  • Machine Learning Engineer
    Coding
    +1 more
  • +1

    "this task is misleading . i used lag(1) and lead(1) cuz it did not say "compare temperature from 2 days before and 1 day before" , it reads to me as if its asking "compare cur temperature to prev and future and see if it rose and fall""

    Erjan G. - "this task is misleading . i used lag(1) and lead(1) cuz it did not say "compare temperature from 2 days before and 1 day before" , it reads to me as if its asking "compare cur temperature to prev and future and see if it rose and fall""See full answer

    Coding
    SQL
  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "sum of continuous subarray and keep checking if arr[i]==arr[j]. if true increase count;"

    Rishabh R. - "sum of continuous subarray and keep checking if arr[i]==arr[j]. if true increase count;"See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • "import random def coin_flip(): x=4*[0]+[1] res=[] for i in range(20): res.append(random.choice(x)) return res res=[0,0] # [head,tail] for j in range(1000): temp=coin_flip() res[0]+=sum(temp) #head res[1]+=(20-sum(temp)) #tail"

    Alireza K. - "import random def coin_flip(): x=4*[0]+[1] res=[] for i in range(20): res.append(random.choice(x)) return res res=[0,0] # [head,tail] for j in range(1000): temp=coin_flip() res[0]+=sum(temp) #head res[1]+=(20-sum(temp)) #tail"See full answer

    Coding
  • Machine Learning Engineer
    Coding
    +1 more
  • "with cte as (select *, row_number() over(order by score desc) as rn from players) select player_name, score, rn as ranking from cte where rn= 4 or rn =6 or rn =11 `"

    Gowtami K. - "with cte as (select *, row_number() over(order by score desc) as rn from players) select player_name, score, rn as ranking from cte where rn= 4 or rn =6 or rn =11 `"See full answer

    Coding
    SQL
  • "def findAlibaba(countOfRooms, strategy): #countofrooms: num rooms #listRooms rooms to look for alibabba possiblePlaces = [] #initialize rooms for i in range(countOfRooms): possiblePlaces.append(True) for i in range(len(strategy)): roomToCheck = strategy[i] #Room is marked as unavailable possiblePlaces[roomToCheck] = False #Next day calculatins nextDayPlaces = [] for j in range(countOfRooms): nextDayPla"

    JOBHUNTER - "def findAlibaba(countOfRooms, strategy): #countofrooms: num rooms #listRooms rooms to look for alibabba possiblePlaces = [] #initialize rooms for i in range(countOfRooms): possiblePlaces.append(True) for i in range(len(strategy)): roomToCheck = strategy[i] #Room is marked as unavailable possiblePlaces[roomToCheck] = False #Next day calculatins nextDayPlaces = [] for j in range(countOfRooms): nextDayPla"See full answer

    Engineering Manager
    Coding
    +1 more
  • "// Helper function to calculate the Euclidean distance between two points function distance(p1, p2) { return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2)); } // A helper function to find the closest pair in a given set of points within the strip function closestPairInStrip(strip, d) { let minDist = d; // Start with the current minimum distance strip.sort((a, b) => a[1] - b[1]); // Sort the strip by y-coordinate for (let i = 0; i < strip.length; i++) { "

    Vishnu V. - "// Helper function to calculate the Euclidean distance between two points function distance(p1, p2) { return Math.sqrt(Math.pow(p1[0] - p2[0], 2) + Math.pow(p1[1] - p2[1], 2)); } // A helper function to find the closest pair in a given set of points within the strip function closestPairInStrip(strip, d) { let minDist = d; // Start with the current minimum distance strip.sort((a, b) => a[1] - b[1]); // Sort the strip by y-coordinate for (let i = 0; i < strip.length; i++) { "See full answer

    Machine Learning Engineer
    Coding
    +1 more
  • "Determine the requirements Perform basic checks on the frontend before submitting to the server Length Check for invalid or required characters Client-side validation messaging Perform more advanced checks on the server if required Does the password include the user's name, etc Handle server-side validation messaging"

    Casey C. - "Determine the requirements Perform basic checks on the frontend before submitting to the server Length Check for invalid or required characters Client-side validation messaging Perform more advanced checks on the server if required Does the password include the user's name, etc Handle server-side validation messaging"See full answer

    Coding
    Data Structures & Algorithms
    +1 more
  • Adobe logoAsked at Adobe 
    +7

    "from typing import List def traprainwater(height: List[int]) -> int: if not height: return 0 l, r = 0, len(height) - 1 leftMax, rightMax = height[l], height[r] res = 0 while l < r: if leftMax < rightMax: l += 1 leftMax = max(leftMax, height[l]) res += leftMax - height[l] else: r -= 1 rightMax = max(rightMax, height[r]) "

    Anonymous Roadrunner - "from typing import List def traprainwater(height: List[int]) -> int: if not height: return 0 l, r = 0, len(height) - 1 leftMax, rightMax = height[l], height[r] res = 0 while l < r: if leftMax < rightMax: l += 1 leftMax = max(leftMax, height[l]) res += leftMax - height[l] else: r -= 1 rightMax = max(rightMax, height[r]) "See full answer

    Software Engineer
    Coding
    +4 more
Showing 241-260 of 363