Software Engineer Data Structures & Algorithms Interview Questions

Review this list of 158 data structures & algorithms software engineer interview questions and answers verified by hiring managers and candidates.
  • 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
    Data Structures & Algorithms
    +1 more
  • Software Engineer
    Data Structures & Algorithms
    +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
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Software Engineer
    Data Structures & Algorithms
    +1 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.

  • 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
  • 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
    Data Structures & Algorithms
    +4 more
  • Google logoAsked at Google 
    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Adobe logoAsked at Adobe 

    "func isMatch(text: String, pattern: String) -> Bool { // Convert strings to arrays for easier indexing let s = Array(text.characters) let p = Array(pattern.characters) guard !s.isEmpty && !p.isEmpty else { return true } // Create DP table: dpi represents if s[0...i-1] matches p[0...j-1] var dp = Array(repeating: Array(repeating: false, count: p.count + 1), count: s.count + 1) // Empty pattern matches empty string dp[0]["

    Vince S. - "func isMatch(text: String, pattern: String) -> Bool { // Convert strings to arrays for easier indexing let s = Array(text.characters) let p = Array(pattern.characters) guard !s.isEmpty && !p.isEmpty else { return true } // Create DP table: dpi represents if s[0...i-1] matches p[0...j-1] var dp = Array(repeating: Array(repeating: false, count: p.count + 1), count: s.count + 1) // Empty pattern matches empty string dp[0]["See full answer

    Software Engineer
    Data Structures & Algorithms
    +3 more
  • +4

    "Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance. Lev(a,b) = len(a) if len(b) == 0 = len(b) if len(a) == 0 = lev(a[1:], b[1:] if a[0] == b[0] = 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:])) https://en.wikipedia.org/wiki/Levenshtein_distance I'm sure some optimizations could be made with heuristic."

    Nicholas S. - "Definitely nice to think of this without memorization, but there is a well known algorithm for this problem, which is the Levenshtein Distance. Lev(a,b) = len(a) if len(b) == 0 = len(b) if len(a) == 0 = lev(a[1:], b[1:] if a[0] == b[0] = 1 + min (lev(a, b[1:]), lev(a[1:], b), lev(a[1:], b[1:])) https://en.wikipedia.org/wiki/Levenshtein_distance I'm sure some optimizations could be made with heuristic."See full answer

    Software Engineer
    Data Structures & Algorithms
    +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
  • Amazon logoAsked at Amazon 

    "na"

    Nishigandha B. - "na"See full answer

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

    "Use Dijkstra's Algorithm with priority queue"

    Karthik R. - "Use Dijkstra's Algorithm with priority queue"See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Dropbox logoAsked at Dropbox 
    Video answer for 'Find duplicate files in a file system.'

    " read_dir(path: str) -> list[str] returns the full path of all files and sub- directories of a given directory. is_file(path: str) -> bool: returns true if the path points to a regular file. is_dir(path: str) -> bool: returns true if the path points to a directory. read_file(path: str) -> str: reads and returns the content of the file. The algorithm: notice that storing all the file contents' is too space intensive, so we can't read all the files' contents to store and compare with each"

    Idan R. - " read_dir(path: str) -> list[str] returns the full path of all files and sub- directories of a given directory. is_file(path: str) -> bool: returns true if the path points to a regular file. is_dir(path: str) -> bool: returns true if the path points to a directory. read_file(path: str) -> str: reads and returns the content of the file. The algorithm: notice that storing all the file contents' is too space intensive, so we can't read all the files' contents to store and compare with each"See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • "As we can pass info to only one child at a time, I told that from any given node, we have to pass the info to that child(of this node) which has the largest subtree rooted at it. To calculate the subtree sizes, I used DFS. And then to calculate the minimum time to pass info to all the nodes, I used BFS picking the largest subtree child first at every node. I couldn't write the complete code in the given time and also made a mistake in telling the overall time complexity of my approach. I think t"

    Lakshman B. - "As we can pass info to only one child at a time, I told that from any given node, we have to pass the info to that child(of this node) which has the largest subtree rooted at it. To calculate the subtree sizes, I used DFS. And then to calculate the minimum time to pass info to all the nodes, I used BFS picking the largest subtree child first at every node. I couldn't write the complete code in the given time and also made a mistake in telling the overall time complexity of my approach. I think t"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Flatiron Health logoAsked at Flatiron Health 
    Software Engineer
    Data Structures & Algorithms
    +2 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
  • Goldman Sachs logoAsked at Goldman Sachs 

    "standard answer for this."

    Shar N. - "standard answer for this."See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
Showing 101-120 of 158