Data Structures & Algorithms Interview Questions

Review this list of 251 data structures & algorithms interview questions and answers verified by hiring managers and candidates.
  • Software Engineer
    Data Structures & Algorithms
    +1 more
  • Uber logoAsked at Uber 
    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • Meta (Facebook) logoAsked at Meta (Facebook) 
    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • LinkedIn logoAsked at LinkedIn 
    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • LinkedIn logoAsked at LinkedIn 

    "#include #include using namespace std; int main() { int n; cin >> n; int a[n]; for(int i=0; i=0 and a[i]<=2) { sort(a[0], a[n]); } } cout << "After sorting array: "; for(int i=0; i<n; i++) { cout << a[i] << " "; } }"

    Shaxboz A. - "#include #include using namespace std; int main() { int n; cin >> n; int a[n]; for(int i=0; i=0 and a[i]<=2) { sort(a[0], a[n]); } } cout << "After sorting array: "; for(int i=0; i<n; i++) { cout << a[i] << " "; } }"See full answer

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

    "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
  • "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 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "Race Condition i,e multiple threads modifying simultaneously can lead to data inconsistency Operations like putIfAbsent() or computeIfAbsent() are not atomoic i.e duplicate entries or missing updates when multiple threads perform operations Data Corruption : during resizing of a hashmap by a thread, if another thread is accessing the same data , buckets can get corrupted, leading to a loss of data"

    Sue G. - "Race Condition i,e multiple threads modifying simultaneously can lead to data inconsistency Operations like putIfAbsent() or computeIfAbsent() are not atomoic i.e duplicate entries or missing updates when multiple threads perform operations Data Corruption : during resizing of a hashmap by a thread, if another thread is accessing the same data , buckets can get corrupted, leading to a loss of data"See full answer

    Data Structures & Algorithms
    Concept
    +1 more
  • Adobe logoAsked at Adobe 

    "#include #include #include using namespace std; void printComs(int prev, int start, int end, int target) { if (start >= end) return; while (start target) { end--; } else { st"

    Iris F. - "#include #include #include using namespace std; void printComs(int prev, int start, int end, int target) { if (start >= end) return; while (start target) { end--; } else { st"See full answer

    Software Engineer
    Data Structures & Algorithms
    +4 more
  • Microsoft logoAsked at Microsoft 

    "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
  • Andela logoAsked at Andela 

    "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
  • LinkedIn logoAsked at LinkedIn 

    "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
  • "I got it right"

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

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "We can use a pool of memory where each index we can store the parent of current index then we can use same lca approach for array instead of pointers."

    Sourav K. - "We can use a pool of memory where each index we can store the parent of current index then we can use same lca approach for array instead of pointers."See full answer

    Software Engineer
    Data Structures & Algorithms
Showing 221-240 of 251