Data Structures & Algorithms Interview Questions

Review this list of 226 data structures & algorithms interview questions and answers verified by hiring managers and candidates.
  • +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

    Data Structures & Algorithms
    Coding
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • 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

    Data Structures & Algorithms
    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
    Data Structures & Algorithms
    +4 more
  • Walmart Labs logoAsked at Walmart Labs 

    "Did the code in Python"

    Divyani .. - "Did the code in Python"See full answer

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

  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • 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

    Data Structures & Algorithms
    Coding
    +1 more
  • Nvidia logoAsked at Nvidia 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "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
    Data Structures & Algorithms
    +1 more
  • Peloton logoAsked at Peloton 

    "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

    Data Structures & Algorithms
    Coding
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "HashMap supports insert, search, delete and retrieve in O(1). It stores data as key value pairs."

    Ina K. - "HashMap supports insert, search, delete and retrieve in O(1). It stores data as key value pairs."See full answer

    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • Intuit logoAsked at Intuit 

    "did well but messed up dequeue"

    Shivani N. - "did well but messed up dequeue"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "add two strings `"

    Jonathan michael J. - "add two strings `"See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • New York Times logoAsked at New York Times 

    "input = [ {"topic": 1, "chapter": 1, "section": 1}, {"topic": 2, "chapter": 2, "section": 1}, {"topic": 3, "chapter": 2, "section": 2}, {"topic": 4, "chapter": 1, "section": 1}, {"topic": 5, "chapter": 1, "section": 1}, {"topic": 6, "chapter": 2, "section": 2}, {"topic": 7, "chapter": 2, "section": 2}, {"topic": 8, "chapter": 2, "section": 3}, ] expected_output = [ {'chapter': 1, 'sections': [ {'section': 1, 'topics': [ {'top"

    Anonymous Unicorn - "input = [ {"topic": 1, "chapter": 1, "section": 1}, {"topic": 2, "chapter": 2, "section": 1}, {"topic": 3, "chapter": 2, "section": 2}, {"topic": 4, "chapter": 1, "section": 1}, {"topic": 5, "chapter": 1, "section": 1}, {"topic": 6, "chapter": 2, "section": 2}, {"topic": 7, "chapter": 2, "section": 2}, {"topic": 8, "chapter": 2, "section": 3}, ] expected_output = [ {'chapter': 1, 'sections': [ {'section': 1, 'topics': [ {'top"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "import java.util.*; public class NetworkTopology { public int topologytype(int N, int M, int[] input3, int[] input4) { if (M != N - 1 && M != N) return -1; // Fast check for invalid cases int[] degree = new int[N + 1]; // Degree of each node (1-based indexing) // Build the degree array for (int i = 0; i < M; i++) { degree[input3[i]]++; degree[input4[i]]++; } // Check for Bus Topology boolean isBus = (M"

    Alessandro R. - "import java.util.*; public class NetworkTopology { public int topologytype(int N, int M, int[] input3, int[] input4) { if (M != N - 1 && M != N) return -1; // Fast check for invalid cases int[] degree = new int[N + 1]; // Degree of each node (1-based indexing) // Build the degree array for (int i = 0; i < M; i++) { degree[input3[i]]++; degree[input4[i]]++; } // Check for Bus Topology boolean isBus = (M"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Visa logoAsked at Visa 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Google logoAsked at Google 
    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Amazon logoAsked at Amazon 

    "USING RECURSION"

    Flora K. - "USING RECURSION"See full answer

    Data Structures & Algorithms
    Coding
Showing 141-160 of 226