I had my interview with Google last week. I won't post the exact question but I'll explain what I was told to do.
You are given a data structure as follows:
{
1: {something: something, something: something, children: [2,4]},
2: {something: something, something: something, children: [3,5]},
3: {something: something, something: something, children: []},
4: {something: something, something: something, children: []},
5: {something: something, something: something, children: []},
}So you need to write a function that gets an id of the object and loops through all children of that object (as you can see id 1 has 2 as child and id 2 has its own children so if your function gets id 1 you need to visit every single child of id 1 as well as id 2).
I used recursion for every element in children array which wasn't the most effecient solution. Does anyone have any ideas?