GodOfCode
BAN USER- -1of 3 votes
AnswersWrite a method that can sort an array of items that can be compared with each others.
- GodOfCode in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer - -1of 3 votes
AnswersDesign and code a way that Facebook could use to suggest new friends you might know.
- GodOfCode in United States| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer
Actually the most query-efficient solution would be to have both a suffix and prefix tree. For an easy analysis, let's assume there we are in one of these cases:
1) 1 extra character somewhere,
2) 1 mispelled characters somewhere,
3) 1 missing character somewhere.
Therefore, the word can be represented as "(part contained in the suffix tree) (character x) (part contained in the prefix tree)". Walk down both trees and at some point we either won't be able to proceed further; intersect the sets containing the following characters and find out the value of x to fix the word.
Have 2 pointers, one points at the first non-even number in the array of evens, the other at the first non-odd number in the array of odds. Swap the numbers and increase both pointers (separately) until they find 2 new numbers to be swapped. In-place and linear time. Java:
public static void arrange(int[] e, int[] o) {
int we=0, wo=0;
do {
while (e[we]%2!=0) we++;
while (o[wo]%2==0) wo++;
int tmp=e[we];
e[we]=o[wo];
o[wo]=tmp;
} while (wo<o.length&&we<e.length);
}
Draw a distribution of sums in the range [0,27] for any three digit number, and you'll figure that the number of cases that adds up to i are (i+1)*(i+2)/2. We have 1000 cases per side, which means 1M total cases: squaring every number of cases that adds to a certain sum will provide the result.
public static int cases() {
int total = 0;
for (int i=0; i<14; i++)
total += (int) Math.pow(i*(i+1)/2, 2);
return total*2;
}
Repcarmelalewis9, Area Sales Manager at AMD
I am fond of reading stories then reading articles which are all about a story of a beautiful nature and ...
P(first wins)=p. When the first players misses (5 out of 6 times) the second finds himself in the same position the other was just before. As a consequence, holds: 1 - p = (5/6)*p. Therefore, P(first wins)=6/11, P(second wins)=5/11.
- GodOfCode April 01, 2013