Skip to main content

Data Structures & Algorithms Interview Questions

Review this list of 271 Data Structures & Algorithms interview questions and answers verified by hiring managers and candidates.
  • Apple logoAsked at Apple 
    Add answer
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • LinkedIn logoAsked at LinkedIn 
    3 answers

    "Count how many 1 and 2. calculate how many remaining items with '0'. Override existing data with knowledge of how many '0','1','2' in that order; TC=O(n), SC=O(1)"

    Konstantin P. - "Count how many 1 and 2. calculate how many remaining items with '0'. Override existing data with knowledge of how many '0','1','2' in that order; TC=O(n), SC=O(1)"See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    1 answer

    "standard answer for this."

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

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    1 answer

    "Function that transforms each elements in a collection and returns new collection with transformed elements"

    Susmita S. - "Function that transforms each elements in a collection and returns new collection with transformed elements"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • 1 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.

  • WhatsApp logoAsked at WhatsApp 
    3 answers

    "Run length encoding. This will preserve order of values in vector."

    Yash S. - "Run length encoding. This will preserve order of values in vector."See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • Microsoft logoAsked at Microsoft 
    1 answer

    "public class BoggleBoard { public static List findWords(char board, Set dictionary) { int rows = board.length; int cols = board[0].length; boolean visited = new booleanrows; int directions = {{1,0}, {-1,0}, {0,1}, {0,-1}}; List result = new ArrayList(); for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { dfs(board, visited, i, j, dictionary, "", result, dire"

    Aniket G. - "public class BoggleBoard { public static List findWords(char board, Set dictionary) { int rows = board.length; int cols = board[0].length; boolean visited = new booleanrows; int directions = {{1,0}, {-1,0}, {0,1}, {0,-1}}; List result = new ArrayList(); for(int i=0; i<rows; i++) { for(int j=0; j<cols; j++) { dfs(board, visited, i, j, dictionary, "", result, dire"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Uber logoAsked at Uber 
    Add answer
    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • Google logoAsked at Google 
    Add answer
    Machine Learning Engineer
    Data Structures & Algorithms
    +2 more
  • 1 answer

    "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "

    Tushar A. - "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "See full answer

    Data Structures & Algorithms
    Coding
  • Apple logoAsked at Apple 
    3 answers

    "Recursion: 0 if NULL, else 1+max(height(left), height(right))"

    Mohith J. - "Recursion: 0 if NULL, else 1+max(height(left), height(right))"See full answer

    Machine Learning Engineer
    Data Structures & Algorithms
    +3 more
  • Apple logoAsked at Apple 
    Add answer
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • LinkedIn logoAsked at LinkedIn 
    1 answer

    "function constructTree(n, matrix) { let parent = []; let child = []; let root = null; for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (matrixi === 1) { parent.push(i); child.push(j); } } } for (let i = 0; i < n; i++) { if (parent.indexOf(i) === -1) { root = i; } } let node = new Node(root); for (let i = 0; i < n; i++) { if (i !== root) { constructTreeUtil(node, parent[i], child[i]); } } return node; }"

    Ugo C. - "function constructTree(n, matrix) { let parent = []; let child = []; let root = null; for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (matrixi === 1) { parent.push(i); child.push(j); } } } for (let i = 0; i < n; i++) { if (parent.indexOf(i) === -1) { root = i; } } let node = new Node(root); for (let i = 0; i < n; i++) { if (i !== root) { constructTreeUtil(node, parent[i], child[i]); } } return node; }"See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • Andela logoAsked at Andela 
    1 answer

    "let str = 'this is a test of programs'; let obj={}; for (let s of str ) obj[s]?(obj[s]=obj[s]+1):(obj[s]=1) console.log(JSON.stringify(obj))"

    Anonymous Emu - "let str = 'this is a test of programs'; let obj={}; for (let s of str ) obj[s]?(obj[s]=obj[s]+1):(obj[s]=1) console.log(JSON.stringify(obj))"See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Apple logoAsked at Apple 
    Add answer
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Add answer
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    1 answer

    "filter function usually exists in some high level programming that adopt FP paradigm. It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate. Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting cleaner code, and reduce the usage of mutable part in the program, lower the possibility of making human mistake. Take Python for example (although const-ness is not exists in Python), assu"

    Weida H. - "filter function usually exists in some high level programming that adopt FP paradigm. It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate. Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting cleaner code, and reduce the usage of mutable part in the program, lower the possibility of making human mistake. Take Python for example (although const-ness is not exists in Python), assu"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "I got it right"

    Rudransh V. - "I got it right"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Bolt logoAsked at Bolt 
    1 answer

    "import re def naturalsortkey(s): Split the string into a list of text and numbers "item10" -> ["item", 10] return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', s)] def natural_sort(arr): return sorted(arr, key=naturalsortkey) \# Example Usage data = ["item10", "item2", "item1", "item20", "2nd item", "1st item"] sorteddata = naturalsort(data) print(f"Standard Sort: {sorted(data)}") print(f"Natural Sort: {sorted_data}") "

    Yitayal B. - "import re def naturalsortkey(s): Split the string into a list of text and numbers "item10" -> ["item", 10] return [int(text) if text.isdigit() else text.lower() for text in re.split(r'(\d+)', s)] def natural_sort(arr): return sorted(arr, key=naturalsortkey) \# Example Usage data = ["item10", "item2", "item1", "item20", "2nd item", "1st item"] sorteddata = naturalsort(data) print(f"Standard Sort: {sorted(data)}") print(f"Natural Sort: {sorted_data}") "See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Adobe logoAsked at Adobe 
    Add answer
    Video answer for 'Print all possible solutions to the N-Queens problem.'
    Data Engineer
    Data Structures & Algorithms
    +2 more
Showing 241-260 of 271