Adobe Interview Question for Developer Program Engineers


Country: United States
Interview Type: In-Person




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

In the question we only have to find the algorithm that finds the largest independent ser. The memoization solution to solve LIS(Largest independent Set) is not acceptable, We are restricted to using loops and tables

- nesh2391 April 12, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I have an idea; however, I am not sure if it is acceptable. As we can have a table, we can use it as the recursion stack and use a while(top>= 0) loop. We implement the memoization algorithm in the loop.

- iroodaz April 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nesh could you please tell me if what I said is acceptable? If it is an acceptable solution, I can post a code for it.
Thanks!

- iroodaz April 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Largest Ind set(X) = MAX { (1 + sum of Largest Ind set for all grandchildren of X),
(sum of Largest Ind set for all children of X) }

- a2 April 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ok, but how will you solve it using a table and loops, remember the final solution must be computed by dynamic programming using loops and a table

- nesh2391 April 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

A DP solution without using recursions. A technique similar to non-recursive DFS is used. A 1xN table is used as a stack. For memoization part, I have put two variables in every node to keep track of the largest independent set in the subtree rooted at that node. One for the case that, that node is included in the set, and another one for the case that, that node is not included in the set.

#include <iostream>

using namespace std;

#define mp make_pair
#define nodeID first
#define state second

typedef pair<int, int> pi;

const int BLACK = 0;
const int GREY = 0;

int max(int a, int b) { return (a < b ? b : a); }

class Node{
	int id;
	int childCount;
	int chosenBestSet;
	int notChosenBestSet;
	int *children;
public:
	int getChildCount()
	{
		return childCount;
	}
	int getChildIdAt(int i)
	{
		return children[i];
	}
	int getChosenBest()
	{
		return this->chosenBestSet;
	}
	int getNotChosenBest()
	{
		return this->notChosenBestSet;
	}
	void setChosenBest(int val)
	{
		this->chosenBestSet = val;
	}
	void setNotChosenBest(int val)
	{
		this->notChosenBestSet = val;
	}
};

int solve(int numOfNodes, pi *stk, Node* nodes, int root)
{
	int top = 0;
	stk[top] = mp(root, BLACK);
	while (top >= 0)
	{
		int topElemId = stk[top].nodeID;
		Node *curNode = &(nodes[topElemId]);
		int childCnt = curNode->getChildCount();

		int topElemState = stk[top].state;

		if (topElemState == GREY)
		{
			int chBestCnt = 0, notChBestCnt = 0;

			for (int i = 0; i < childCnt; i++)
			{
				Node curChild = nodes[curNode->getChildIdAt(i)];

				chBestCnt += curChild.getNotChosenBest();
				notChBestCnt += max(curChild.getChosenBest(), curChild.getNotChosenBest());
			}

			curNode->setChosenBest(chBestCnt);
			curNode->setNotChosenBest(notChBestCnt);

			top--;

			continue;
		}

		stk[top].state = GREY;

		if (childCnt == 0)
		{
			curNode->setChosenBest(1);
			curNode->setNotChosenBest(0);

			top--;

			continue;
		}

		for (int i = 0; i < childCnt; i++)
		{
			int childId = curNode->getChildIdAt(i);
			stk[++top] = mp(childId, BLACK);
		}

	}

	return max(nodes[root].getChosenBest(), nodes[root].getNotChosenBest());
}

- iroodaz April 14, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This is how i would solve this :

Do a level order traversal of the tree iteratively (using Queue).So your end output should given an array of values which represent the sum of nodes at every level. Now inorder to satisfy the problem we use a DP approach and start from the lower to higher levels of tree.

MaxIndependent(i) = At 'ith' level the maximum independent set (i am not sure if maximum means cardinality or the sum of elements of nodes - change accordingly).

MaxIndependent(i) = Max( MaxIndependent(i-1) , SumArray[i] + MaxIndepedent(j) any of the below level j <i )

the base case is for the lowest level

- Sorrowfull Blinger September 13, 2014 | 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