Zoho Interview Question for Senior Software Development Engineers


Team: Theriyathu
Country: India
Interview Type: In-Person




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

First you can build a map of relationships. In java it might look like:

Map<String, List<String>> relations = new HashMap<String, List<String>>();

Then you enter your values into the map (i.e. "Syam" would be the key for an ArrayList<String> containing "Ram" and "Akil")

Once we have our map, we can use getDescendantCount("Syam", 2) on the below function to get our desired output.

    private int getDescendantCount(String key, int depth) {
        int descendant  = 0;

        if(depth <= 0) { return 1; }
        if(!relations.containsKey(key)) { return 0; }

        for(String child : tree.get(key)) {
            descendant  += getDescendantCount(child, depth - 1);
        }

        return descendant  ;
    }

- Bradley Wheeler December 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is tree?

- Manuj October 28, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is tree?

- Manuj October 28, 2020 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is finding the first level parents is part of the task or it's an input?

- Nikolay December 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is simple if we make father childList Map.
1. Create Map<Father, List<Child>> by iterating over pairs.
2. For level =1 map.get(father) which in turn returns childList (List<Child>) totalChildren = childList.size()
3. For level = 2 , Iterate over childList and each element of childList is now father so map.get(childList(i)) and add the size of return value for totalChildren.

repeat same for the next level.

- Avinash Kumar December 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function getChildren (map, name, level) {
	if (level === 1) {
		return map[name]
	}
	var children = []
	for (var i = 0; i < map[name].length; ++i) {
		children = children.concat(getChildren(map, map[name][i], level - 1));
	}
	return children;
}
module.exports = function (A, name, level) {
	var map = {}
	for (var i = 0; i < A.length; ++i) {
		var child = A[i][0];
		var father = A[i][1];
		map[father] = map[father] || [];
		map[father].push(child);
	}
	var children = getChildren(map, name, level);
	return [children, children.length];
}

var children = module.exports([
	['Ram', 'Syam'],
	['Akil', 'Syam'],
	['Nikil', 'Ram'],
	['Subhash', 'Ram'],
	['Karthik', 'Akil']
], 'Syam', 2);

console.log(children);

- srterpe December 20, 2016 | 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 PrintChildCound {

  int countChildLevel(Node root, int level, int currentLevel, int total) {
    if(root == null) {
      return 0;
    }
    if(level == currentLevel) {
      System.out.println(root.val);
      total++;
    }
    for(Node node : root.list) {
      total = countChildLevel(node, level, currentLevel+1, total);
    }
    return total;
  }
  public static void main(String... args) {
    Node shyam = new Node("Shyam");
    Node akhil = new Node("Akhil");
    shyam.hasChild(akhil);
    Node ram = new Node("Ram");
    shyam.hasChild(ram);

    ram.hasChild(new Node("Nikil"));
    ram.hasChild(new Node("Subhash"));

    akhil.hasChild(new Node("Karthik"));

    System.out.println(new PrintChildCound().countChildLevel(shyam, 2, 0, 0));
  }
}
class Node  {
  Node(String val) {
    this.val = val;
  }
  void hasChild(Node node) {
    list.add(node);
  }
  String val;
  List<Node> list = new ArrayList();
}

- Weshall December 20, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;

public class NumOfChildrenImpl{
  Map<String,String> relationships;
  
  public NumOfChildrenImpl(Map<String,String> relationships){
    this.relationships = relationships;
  }
  
  public int getNumOfChildren(String fatherName,int level){
    Set<String> directChildren = new HashSet<>();
    for(Map.Entry<String,String> entry:relationships.entrySet()){
      if(entry.getValue().equals(fatherName)){
        directChildren.add(entry.getKey());
      }
    }
    
    if(level<=1){
      //for(String childName:directChildren){
      //  System.out.print(" " + childName + " ");
      //}      
      
      return directChildren.size();
    } 
    
    int numOfIndirectChildren=0;
    
    for(String childName:directChildren){
      numOfIndirectChildren+=getNumOfChildren(childName,level-1);
    }
    
    return numOfIndirectChildren;
  }
}

- dvizelman December 21, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One way could be iterate over the childs starting from father and increament a count. Once you reach n-1 count then push all those childs to a stack or somewhere. Now, you can simply list their childrens from hashmap or the input given.

- amiedeep December 21, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
function go(name, level) {

var input = [
['aa', 'bj'],
['bb', 'bj'],
['cc', 'wk'],
['bj', 'kong'],
['wk', 'kong'],
];

var tree = {};

for(var i in input) {
var child = input[i][0];
var parent = input[i][1];

if(!tree[parent]) {
tree[parent] = {};
}

if(!tree[parent][child]) {
tree[parent][child] = {};
}
}

var count = 0;
var curKeys = [name];

while(count < level) {
var keys = [];
for(var i in curKeys) {
keys = keys.concat( Object.keys(tree[curKeys[i]]) );
}
curKeys = keys;
count++;
}
return curKeys.length;
}
}}

- kongfamily0804 January 05, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream>
#include<string>
using namespace std;

struct s
{
string child;
string parent;
};


int find(s cp[],string name,int level,int l,int n)
{
int i;
int count=0;
if(l==level)
return 1;
for(i=0;i<n;i++)
{
if(cp[i].parent==name)
{
count=count+find(cp,cp[i].child,level,l+1,n);
}
}
return count;
}

int main()
{
int n,i,level,l=0,count=0;
cin>>n;
s cp[n];
string name;
for(i=0;i<n;i++)
{
cin>>cp[i].child;
cin>>cp[i].parent;
}
cin>>name>>level;
cout<<find(cp,name,level,l,n);
}

- Anonymous February 27, 2018 | Flag Reply


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