JobHunter
BAN USER
- 0of 0 votes
AnswersWe have a job sequence like this.
- JobHunter in United States
A
/ \
B --C
This case A's dependent jobs are B & C
B's dependent job is C
C's Dependent job is null
If we need to complete any of the steps we should need to complete the dependent object.
This case job sequence will be C->B->A
Can anyone comeup with simple o(n) solution for this?| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm - 0of 0 votes
AnswersDesign the system for threater reservation system. for example Seat or chairs are organized in the form of rows and columns. When the first person come and book the ticket need to provide a seat on the middle of the last row. When next person come we have to provide empty space between the existing audience and book the ticket for the set of people. How we will design this system?
- JobHunter in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Application / UI Design - 0of 0 votes
AnswersIn a nxn matrix, data provided like below. We need to find the groups of 1s with the adjustent column and row.
- JobHunter in United States
eg)
0 0 0 0
1 1 1 1
0 0 0 0
group of 1 is 1
1 0 0 0
0 0 0 1
1 1 0 0
group of 1s is 3
Any thought how to get the set of groups.| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Matrix - 0of 0 votes
AnswersFor the given number need to find out the possible BST. eg, if the given number is n means we should find BSTs using 1,2..n. n=5 means figure it out using 1,2,3,4,5, how many BST we can make?
- JobHunter in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm
Here is the C# version for the same
public static void printParen(int pos, int open, int close, char[] str, int n)
{
if(close == n)
{
Console.WriteLine(new string(str));
return;
}
else
{
if(open > close)
{
str[pos] = '}';
printParen(pos + 1, open, close + 1, str, n);
}
if(open < n)
{
str[pos] = '{';
printParen(pos + 1, open + 1, close, str, n);
}
}
}
You can find out this one using distance.
1. You should know the orignal header in the linked list eg) 1
2. Form a Array with given linked element with distance
list=1->2->3->4->5
eg)
a(1)->0,a(2)->1,a(3)->2,a(3)->3,,,,
in this case we need to move forward 3
eg)2
for the backward cursor set the orginal header and set the distance as -{orginal position of newpointer}-{each node position}
as per the second example
a(1)->-4,a(2)->-3,a(3)->-2,a(3)->-1,a(4)->0
This will easy for us to figure it out.
void treeToDoublyList(treeNode *rootNode, treeNode *& prevNode, treeNode *& head)
{
if (!rootNode)
return;
treeToDoublyList(rootNode->pLeft, prevNode, head);
rootNode->pLeft = prevNode;
if (prevNode)
prevNode->pRight = rootNode;
else
head = rootNode;
treeNode *rNode = rootNode->pRight;
head->pLeft = rootNode;
rootNode->pRight = head;
prevNode = rootNode;
treeToDoublyList(rNode, prevNode, head);
}
treeNode* treeToDoublyList(treeNode *rootNode)
{
treeNode *prev = NULL;
treeNode *head = NULL;
treeToDoublyList(rootNode, prev, head);
return head;
}
BTW, I have come up with the below algorithm
- JobHunter July 12, 2012int[] plusplus(int[] inArr)
{
Find length of input Array;
Define outputArraylength={length of input Array}; + 1;
declare outputArray
Declare carry variable
decrement OutputArraylength
Loop (outArraylen>=0)
{
if (inlen == (inArr.Length - 1))
carry = inArr[inlen--] + 1;
else if (inlen>=0)
carry += inArr[inlen--];
outArr[outlen--] = carry % 10;
carry /= 10;
}
return outputArray;
}