Skip to main content

Data Structures & Algorithms Interview Questions

Review this list of 264 Data Structures & Algorithms interview questions and answers verified by hiring managers and candidates.
  • "hash maps work in key value pair. The keys are hashed with a hash algorithm and resulting hashcode(integer) with related value are stored. Accessing a value, removing an element, Searching the hash map: 1) The hash map value can be accessed in O(1) time once you know the key. 2) If the key is not known, the hashmap value can be accessed in O(n) since you have to iterate atleast once. "

    Kavithadevi P. - "hash maps work in key value pair. The keys are hashed with a hash algorithm and resulting hashcode(integer) with related value are stored. Accessing a value, removing an element, Searching the hash map: 1) The hash map value can be accessed in O(1) time once you know the key. 2) If the key is not known, the hashmap value can be accessed in O(n) since you have to iterate atleast once. "See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Software Engineer
    Data Structures & Algorithms
    +1 more
  • "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed. Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach. I discussed few corner scenarios with the interview"

    Rishabh N. - "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed. Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach. I discussed few corner scenarios with the interview"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."

    Mourya C. - "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."See full answer

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

  • Meta logoAsked at Meta 
    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 

    "A doubly linked list is like a train where the engine is its head, and the compartments doors are interconnected, you can travel though them. The last compartment is the tail and is not connected with anything. Following is a visual: Head C1 C2 C3....Cn Tail Pseudocode: **class Node: Data pointer next pointer prev End class DLL = NULL //pointer to list insertion: if DLL is NULL: head = new Node() DLL = head DLL.prev = NU"

    Rasika D. - "A doubly linked list is like a train where the engine is its head, and the compartments doors are interconnected, you can travel though them. The last compartment is the tail and is not connected with anything. Following is a visual: Head C1 C2 C3....Cn Tail Pseudocode: **class Node: Data pointer next pointer prev End class DLL = NULL //pointer to list insertion: if DLL is NULL: head = new Node() DLL = head DLL.prev = NU"See full answer

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

    " First, sort the array in ascending order. This ensures that we can easily check the triangle inequality condition. Use a loop to iterate through the array. For each triplet of consecutive elements, check if they satisfy the triangle inequality condition a+b>ca+b>c. As soon as you find a valid tuple, return it. If no valid tuple is found, return null. This approach is efficient with a time complexity of O(nlog⁡n)O(nlogn) due to the sorting step, followed by a linear scan of the array"

    Shivam P. - " First, sort the array in ascending order. This ensures that we can easily check the triangle inequality condition. Use a loop to iterate through the array. For each triplet of consecutive elements, check if they satisfy the triangle inequality condition a+b>ca+b>c. As soon as you find a valid tuple, return it. If no valid tuple is found, return null. This approach is efficient with a time complexity of O(nlog⁡n)O(nlogn) due to the sorting step, followed by a linear scan of the array"See full answer

    Machine Learning Engineer
    Data Structures & Algorithms
    +1 more
  • Software Engineer
    Data Structures & Algorithms
    +1 more
  • Google logoAsked at Google 
    Machine Learning 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
  • LinkedIn logoAsked at LinkedIn 
    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Apple logoAsked at Apple 

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

    "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
  • Uber logoAsked at Uber 
    Machine Learning 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
  • "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
Showing 221-240 of 264