↳
The question is a variation of the commonly asked problem of finding the start/end index of a sorted array that has been rotated. Takes O(log n) time. Less
↳
You can solve this question using ternary search
↳
First, binary search will not work since just looking at a single point will not tell you if it's on the decreasing or increasing side of the curve. What you need is modified binary search. Looking at position i check position i+1 if it's increasing then search right otherwise search left; Code: int peak(vector V, int i, int iStart, int iEnd){ assert( i >= 0 && i = 0 && iStart = 0 && iEnd < V.size()); assert( iStart <= i && i <= iEnd ); if (i == iEnd) return i; int iCurr = V[i]; int iNext = V[i+1]; int iStartNew = iStart; int iEndNew = iEndl if( iCurr < iNext ) iStartNew = i; else iEndNew = i; int iNew = (iEndNew-iStartNew)/2; if( iNew == i ) iNew++; return peak(V, iNew, iStartNew, iEndNew); } Less
↳
Acceleration
↳
Guys...the (time) derivative of velocity is, without a doubt, acceleration.
↳
dx/dt; delta of distance over delta of time
↳
DFS inorder return first k visited nodes (using auxiliary array)
↳
using a rather complicated recursion.
↳
look number of values on the left of the current node, if adding this node we get k - this is the node we are looking for. Less
↳
int S=0; int i; for (i=1, i<=5, i++) S=S+rand5(); return ( S % 7) + 1; S spans 5 to 25 (inclusive, which are 21 values evenly/uniformly spread) Less
↳
The above solution (with the sum) is not correct because, for example, you have several “options” to get to a sum of 6 (1+2+1+1+1, 2+1+1+1+1 etc...), but only one option to get to a sum of 5 (get 1 five times). So the 5 to 25 range is not evenly distributed. You are more likely to get certain numbers. So the rand7 does not return 1-7 uniformly. Less
↳
int a = rand5(), b = rand5() while (a*5 + b < 10) {a = rand5(), b = rand5()} return (a*5 + b) % 7 Less
↳
Hi, Can you share what kind of questions were asked in the 1st technical test?
↳
Well first round was basic OOPS knowledge. Since it's been more than 2 months, I do not exactly recall all the questions but it was straight forward. Less
↳
Regarding main face to face interview, I've already mentioned two questions in my original post. Less
↳
Not enough information. No idea how many branches there are or what is the location of each one. And what kind of tree could you scale all the way to the top while fully supporting your weight? Was this a 100-foot tree that was cut off after 60 feet? Less
↳
20 branches
↳
Divide 60 by 3.
↳
when you call fn() its scope is in global. The function call should be scoped properly to work. You should use call or apply to make it work. Less
↳
It's essential to demonstrate that you can really go deep... there are plenty of followup questions and (sometimes tangential) angles to explore. There's a lot of Software Engineer III experts who've worked at PayPal, who provide this sort of practice through mock interviews. There's a whole list of them curated on Prepfully. prepfully.com/practice-interviews Less
↳
fn is "Bob" and not a method.
↳
Using a HashMap to store existing id's
↳
Didn't get the question. list[String] will have nodes all the way down to the leaf or just one or two immediate children ? Less
↳
I would use a HashMap , A, for node.id -> Node Object. Meaning that when reading a line I would create a Node Object with the given id. And child Id which appears in this map (A) I will add a pointer to it from the parent. If the child id is missing, then I will add the parent to another HashMap, B, which stores child.id -> [List of parents]. So that actually when reading a line and creating a new Node, I will also look at HashMap B, and update all it's parents (and remove them from map B). Less
↳
@M: it's a pretty common question irrespective of the nationality of the interviewer. I was asked the same question by a Caucasian guy at a different firm and I didn't get the job - not because of my (or his) nationality, but because I wasn't technically strong enough. Less
↳
M. I am here in states and am Indian and I bet you have no idea how difficult Indian interviewers are! If you are an Indian and he is Indian too, he would give you a benefit of doubt! Yes some of us are like that, but I guess every where there are some folks like that! Cheers! Less
↳
what kind of entrance exam? Such stupid interview, guess pretty much like those in India. My expereince was if interviewer & candidate are from India, no such testing etc. If interviewer is from India and candidate is of other nationality, yes, because that will give the interviewer an excuse not to hire. Less
↳
The above answer is wrong, consider the tree below: 10 / \ 5 15 / \ 12 25 The post order traversal is 5, 12, 25, 15, 10 but the answer should be 12, 25 (or 25, 12), 5, 15 (or 15, 5) and 10 The correct solution would be to do a BFS from the room using a queue. After visiting a node, add it to a stack and continue. When done the traversal, loop the stack popping elements and printing to screen. Less
↳
Do an in level order traversal and place each node visited into a stack. Then, pop each element from the stack. The elements will pop out in the reverse order. Less
↳
With no additional restrictions, this sounds as though it is simply a post-order traversal of the tree. Less