## Flipkart Interview Question for Senior Software Development Engineers

Country: India
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````public class Node<T> where T : IComparable
{
public T Data { get; set; }

public List<Node<T>> Childern { get; set; }

public Node(T data)
{
this.Data = data;
this.Childern = new List<Node<T>>();
}

public void AddNode(Node<T> n)
{
}

public int FindMaxDepth()
{
return FindMaxDeptOnNode(this);
}

private int FindMaxDeptOnNode(Node<T> n)
{
if (n == null)
{
return 0;
}

int kidDepth = 0;
int maxDepth = 0;

for (int i = 0; i < n.Childern.Count; i++)
{
kidDepth = FindMaxDeptOnNode(n.Childern[i]) + 1;
if (kidDepth > maxDepth)
{
maxDepth = kidDepth;
}
}

return maxDepth;
}
}``````

Comment hidden because of low score. Click to expand.
1
of 1 vote

Both BFS and DFS should work, though I will prefer BFS.

Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.ArrayList;
import java.util.List;

public class Node {
List<Node> nodelist = new ArrayList<Node>();
public void addNode(Node node){
}
static int count;
static int max;
//Assuming if a node has a child, path length between them is 1
public static int maxPathLength(Node node){
searchNode(node);
return max;
}
public static void searchNode(Node node){
if(count>max)
max = count;
count++;
for(Node cNode : node.nodelist){
searchNode(cNode);
}
count--;
}
}

Comment hidden because of low score. Click to expand.
0

Piece of JAVA code is always more readable

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.