Google Data Structures & Algorithms Interview Questions

Review this list of 25 Google data structures & algorithms interview questions and answers verified by hiring managers and candidates.
  • Google logoAsked at Google 

    Permutations

    IDE
    Medium

    "function permute(nums) { if (nums.length <= 1) { return [nums]; } const prevPermutations = permute(nums.slice(0, nums.length-1)); const currentNum = nums[nums.length-1]; const permutations = new Set(); for (let prev of prevPermutations) { for (let i=0; i < prev.length; i++) { permutations.add([...prev.slice(0, i), currentNum, ...prev.slice(i)]); } permutations.add([...prev, currentNum]); } return [...permutations]"

    Tiago R. - "function permute(nums) { if (nums.length <= 1) { return [nums]; } const prevPermutations = permute(nums.slice(0, nums.length-1)); const currentNum = nums[nums.length-1]; const permutations = new Set(); for (let prev of prevPermutations) { for (let i=0; i < prev.length; i++) { permutations.add([...prev.slice(0, i), currentNum, ...prev.slice(i)]); } permutations.add([...prev, currentNum]); } return [...permutations]"See full answer

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

    "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."

    Prashant Y. - "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."See full answer

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

Showing 21-25 of 25