chenming831
BAN USERIt is easy to think out an extreme case to make the hierarchical way fail. But that extreme case very unlikely exists in real systems. Actually, the hierarchical way is kind of statistics sampling. If you always use extreme cases, no probability and statistics will exist.
- chenming831 June 20, 2010Hi. What you said is correct. But the hierarchical way only approximates the 65%-the percentile of 1B requests, by assuming the processing time of all requests are uniformly distributed within a certain range. If the estimation window is large enough, this assumption should be OK.
It is easy to think out an extreme case to make the hierarchical way fail. But that extreme case very unlikely exists in real systems. Actually, the hierarchical way is kind of statistics sampling. If you always use extreme cases, no probability and statistics will exist.
I got a method:
1)Define a signature for each int. For example, an integer like 1111,0011,1111,0000 will have a signature in string as "14021604". The even char in the signature is either 0 or 1, while the odd char is the # of consecutive 0 or 1, which is represented in hex (since the consecutive # of 0 or 1 may be larger than 10, but we only want represent the # as one char).
2)therefore, we can convert the whole array into a string.
3)Go through the whole string, it is easy to get the longest consecutive sequence of 1 and its bit position.
For example, we have an array like: 3, 4, 5, 7, if we represent each int as 4 bits, we will have 0011, 0100, 0101, 0111. Then we have the signature: "0212","011102","01110111","0113".
Then we go through the string, we can get the longest consecutive sequence is 3.
Are the two links sorted? If they are sorted, it is very easy.
- chenming831 June 17, 2010gevorgk: gorgous solution!
- chenming831 June 17, 2010Establish a hash. The complexity is O(n).
Int findFirstNonrepeatedChar(char* str)
{
If(str == NULL) return -1;
Int hash[MAX_CHAR];
Int I;
For(i=0; str[i]!=’\0’;i++)
{
Hash[str[i]]++;
}
For(i=0;str[i]!=’\0’;i++)
{
If(hash[str[i]] == 1)
{
Return str[i];
}
}
}
tetura's conditional branches are exactly the same as ap's, though the logic is clearer.
- chenming831 June 16, 2010I guess the meaning of the question is to find the biggest difference but the large element appearing after the small element in an array.
Therefore, keep two variables, the first one keeps the current min in the array, the second variable keeps the biggest the diff. Scan the whole array, it is done.
the 3rd way is wrong. y is a constant address pointing to a struct object in the stack. y cannot be changed.
- chenming831 June 16, 2010a lot of unclear questions here, which are really annoying. kind of wasting time!
- chenming831 June 16, 2010How can you say that, please test it by this example:
4572186, the missing one is 3, but your method gets 6
The code given by gevorgk is wrong!
Assuming an array: 4572186, the missing one is 3. Following the codes, I get:
4 5 7 2 1 8 6
2 5 7 4 1 8 6
2 1 7 4 5 8 6
2 1 6 4 5 8 7
2 1 6 4 5 -1 7 (skip 4 and 5)
the solution given by your code is 6, but the true answer is 3.
weird question.
- chenming831 June 16, 2010I think the problem of this question is not to get the diameter but to get two ends of nodes B&I. Who have a good solution to print out B&I after calculating the diameter?
- chenming831 June 16, 2010I think DFS is equivalent to post-order transverse, not to in-order or pre-order. Using a stack to post-order transverse a binary tree has pretty complicate logic.
- chenming831 June 16, 2010int printPath(NODE* root, int v)
{
if(root == NULL) return 0;
if(root->v == v)
{
printf("%d<-", root->v);
return 1;
}
if( printPath(root->left,v) || printPath(root->right, v))
{
printf("%d<-", root->v);
return 1;
}
else
{
return 0;
}
}
problem 1: the only chance of no collision is that all ants walk in clockwise or counter-clockwise way, therefore, the probability of no collision is (1/2)^3*2 = 1/4.
problem 2: step 1, divide them into 3 groups each with 3 balls. Weigh any two of them. If equal, then the 9th is in the 3rd group; otherwise weigh one of the two and the 3rd group to decide which group the 3rd is in. At the same time, we can know whether the 9th ball is lighter or heavier. The total number of weighing is 2 in this step; Step 2, divide the group in which the 9th is in into 3. Pick any two of them to weigh. If equal, the third one is the 9th ball. Otherwise, pick up the lighter/heavier one as the 9th ball. (The information of being lighter or heavier has been got in the first step.) Therefore, we need totally 3 weighings.
Problem3: Cut the cube apart and put them in a 2-dim surface. Draw a line connecting the two vertex. That line is the shortest.
Get the difference between two elements. Decreasing is - while increasing is +. Then check the changing point.
for example 94512678, we get 1459 8762. Then we have +++ ----, therefore, the inflexion point is 4.
Then how can a calculator knows how many multiplications it should do since there is no addition? Anybody can write down the codes?
- chenming831 June 04, 2010Assume it is a binary tree. If it is n-ary tree, just add a little more codes.
Int isInclude(NODE* node1, NODE* node2)
{
if(node1 == NULL && node2 == NULL) return 1;
if(node1!=node2 &&(node1==NULL || node2==NULL)) return 0;
if(node1->data == node2->data)
return (isInclude(node1->left, node2->left) && isInclude(node1->right, node2->right));
if(node1->data!=node2->data)
return (isInclude(node1->left, node2) || inInclude(node1->right, node2));
}
it does not work
- chenming831 May 31, 2010Add a new item in each node that records the # of visits. Go through the two lists, and increase the # of visits by one upon each visit. Go through anyone of the list, to check if there are any nodes with the # of visits larger than 1.Complexity = O(2*N+M)
- chenming831 May 31, 2010not work for bit vector. how do you know which char is the first non-repeated one?
- chenming831 May 30, 2010who has a better solution?
- chenming831 May 30, 2010I also think out another way by using histogram. If we know the general range of the processing time, for example, from 1ms to 10ms. We divide the range into many subintervals with a certain good enough granularity. Then we count the # of requests whose processing time falls into each subintervals. Finally, we can get a histogram, and we can approximately estimate the 65-th percentile.
Compared with the solution above, the good thing is that we can get any x-th percentile from the histogram without any other overhead; the bad thing is that the percentile is estimated and is not so accurate as that of the solution above.
I guess we can do it in a hierarchical way. We only calculate the 65-th processing time in every window of 1000 requests. Put the 65-th processing time of every 1000 requests into another window (a higher level), which records 1000 values again. On a higher higher level, we can record another 1000. As a result, we can record 10^9 requests by using a storage of 3000 requests.
- chenming831 May 30, 2010excellent solution!
- chenming831 May 16, 2010What do you mean by "memmove does not use a buffer". memmove DOES use a buffer!
- chenming831 May 16, 2010If you use more space to make time less, it is reasonable. Otherwise, it is just a inferior method.
- chenming831 May 16, 2010Each sessionID may have multiple pageIDs. How can you achieve this "Split big file into small 100 files from 00.txt to 99.txt by using last two digit of pageId(assuming that pageid > 10). Now all pageIds will grouped in different files."
More explanations?
Dont understand how it works. What do you mean?
- chenming831 April 25, 2010Whether the child process contains two threads depends the place where the two threads in the parent are created. If they are created after the creation of the child process, the child process will also have two threads. If we want to make threads safe, we should not protect the global variables in the same process. Is it right?
- chenming831 April 24, 2010I think what Patron on April 21, 2010 have said is basically correct to find the repeated digits. But to get a final correct answer, we need more logic.
- chenming831 April 24, 2010This is only correct for integer arrays. The question does not say the array is integer. If it is float, the method fails.
- chenming831 April 24, 2010This is only correct for integer arrays. The question does not say the array is integer. If it is float, the method fails.
- chenming831 April 24, 2010who can explain the question a little bit more? I do not understand what it is talking about.
- chenming831 April 24, 2010who can give a solution to this question?
- chenming831 April 17, 2010
RepVictoriaMitchell, Animator at ABC TECH SUPPORT
I am an Analysis Manager.I have 7 years of experience in leveraging data analysis to develop. And I love ...
Repsheilabjones023, abc at 8x8
Hello,I am a Press operator. I completed my degree from Chicago and now am a Press operator in Lechmere ...
RepHondaRonda, Accountant at Achieve Internet
I am a communications specialist who develops and nurtures relationships between an organisation, members of the media and the public ...
RepReginaCollins, Accountant at 8x8
Greetings! I'm Regina Collins, a seasoned professional in the dynamic world of procurement and supply chain management. With over ...
RepStanPhillips, Animator at AMD
StanPhillips, a Landscape architect . I have been working at Pro Property Maintenance it's almost 10 years . I also help ...
Reprothymellen, Consultant at Accolite software
I am a Correctional officer . I have the primary role of maintaining order within a detention facility. My hobby is ...
RepElaKim, Accountant at A9
Highly efficient and diligent administrative office professional with seven years of experience in management. Capable leader with excellent skills in ...
Repnetteyoder22, Applications Developer at 247quickbookshelp
Nette, transportation inspector inspects goods and equipment associated with transporting people or cargo to ensure safety. I typically work for ...
RepOwenKary, Analyst at ASU
I am an experienced software engineer with a passion for java developing innovative programs that expedite the efficiency and effectiveness ...
RepVirginiaSlifer, Analyst at A9
In my professional life, I am a dedicated genetics nurse with a deep interest in understanding the intricacies of human ...
RepSuziCorni, Accountant at A9
I have strong critical and analytical skills with reading, writing, and comprehension. I have exceptional speaking skills without losing train ...
RepYaniraBryant, Accountant at CGI-AMS
I am Yanira , a writer by fate. Went from writing for media outlets to exploring the world of content creation ...
RepKeciaFowler, Area Sales Manager at Auto NInja
My name is Kecia and I am a results-oriented Real Estate Appraiser Trainee with a strong determination to perform great ...
RepHenryLee, Accountant at AMD
I am a creative and 5 years experienced beautician. I have experience with most cosmetology tools, including razors, nail clippers ...
RepBriannaWright, Analyst at A9
I am a skilled project manager with years of exemplary service in diverse IT roles. I am passionate about utilizing ...
RepElizabethMaxim, Android test engineer at AMD
A financial economist is responsible for the production and distribution of goods and services. We are also responsible for collecting ...
Repjoyross801, Blockchain Developer at ASAPInfosystemsPvtLtd
JoyRoss, a Paper products machine operator, operates and monitors machines which produce boxes, envelopes, bags and other goods from paper ...
why not?
- chenming831 July 27, 2010