hm
BAN USER- 0of 0 votes
AnswersDesign a train system which suggests shortest path and transfer needed to reach from source to destination. What can be the optimization.
- hm in United States
For example:
A system may have 10 trains from t1 to t10.
There are total 100 stops in the system s1 to s100.
Each train has fixed set of stops. You could allow to change and transfer train of source and destination does not cover using just 1 train.
What all can be APIs, data structure, optimizations scalable option.| Report Duplicate | Flag | PURGE
Software Engineer Algorithm Problem Solving Software Design System Design Trees and Graphs design - 2of 2 votes
AnswersGiven an array of task and k wait time for which a repeated task needs to wait k time to execute again. return overall unit time it will take to complete all the task.
- hm in United States
Example:
1. A B C D and k = 3
ans: 4 (execute order A B C D)
2. A B A D and k = 3
ans: 6 (execute order A B . . A D)
3. A A A A and k =3
ans: 13 (A . . . A . . . A . . . A)
4. A B C A C B D A and k = 4
ans: 11 (A B C . . A .C B D A )| Report Duplicate | Flag | PURGE
Twitter Software Engineer Algorithm - 1of 1 vote
AnswersDesign a data structure which should have following operation. Insert, Delete, Random access
- hm in United States| Report Duplicate | Flag | PURGE
Google Software Engineer Data Structures
agree it should use stack to traverse nodes instead of queue. Revised above logic,
{{
void printPostOrderIterative(TreeNode* root)
{
if(!root)
return;
stack<TreeNode*> store;
stack<TreeNode*> traverse;
traverse.push(root);
while (!traverse.empty())
{
TreeNode* element = traverse.top();
store.push(traverse.top());
traverse.pop();
for (int i = element->children.size() -1 ; i >= 0; i--)
{
traverse.push(element->children[i]);
}
}
while (!store.empty())
{
printf("%d\n", store.top()->data);
store.pop();
}
}
}}
To find kth largest or smallest number, use quick select algorithm. Check out wikipedia.
- hm September 18, 2015