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)
        {
            this.Childern.Add(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;
        }
    }

- wmg August 21, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

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

- Anonymous October 09, 2014 | Flag Reply
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){
nodelist.add(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--;
}
}

- bsinha November 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Piece of JAVA code is always more readable

- Akshay December 13, 2014 | Flag


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More