yash
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
private void execute() {
int[] input = new int[]{0, 9, 1, 2, 3};
if (input.length == 0) {
return;
}
int minHigh = input[0], maxLow = input[input.length - 1], i = 0, j = input.length - 1;
for (; i < j; ) {
int high = Math.max(minHigh, input[i]);
int low = Math.min(maxLow, input[j]);
if (high < low) {
i++;
maxLow = low;
minHigh = high;
} else {
if (low <= high) {
i--;
j--;
maxLow = low;
}
}
}
if (i == j)
System.out.println(i);
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
So you want to have one (or more) sender who reads the file and multiple machines processing and building the output file. Depending on the size of each machine's memory, we need to come up with hashing function. Run the id through has and find out which machine (1-16 for ex) will be processing it. Note that both files with same id has to go to the same machine to process it.
- yash October 31, 2021Each machine will receive the id -> name or id ->address and it needs to merge the records by keeping the id in hashSet.
Once all the machines are done processing it, they can write to single file one by one.
int ids won't be usually preferred as it does not have enough range. GUID is usually preferred and in this case you can simply take the first char of GUID and send it to corresponding machine if we decide to take 16 machines each capable of running
memory = total possible number of Ids / 16