A company is performing an analysis on the
computers at its main office. The computers are
spaced along a single row. For each group of
contiguous computers of a certain length, that is,
for each segment, determine the minimum amoun
of disk space available on a computer. Return the
maximum of these values as your answer.
Answers
Answer:
d
Explanation:
syu6hdkbjgyiighsyayzhvuvf undu hbhx uhi hr cujc. hhjuii
Answer:
int maxOfAllMin(vector<int> &hardDiskSpace, int segmentLength) {
int n = hardDiskSpace.size();
// Find The Minimum HDD Space in the First Segment;
vector<int> segment;
map<int, int> mp;
multiset<int> minQueue;
int ans = -1, mnTemp;
for (int i = 0; i < segmentLength; i++) {
segment.push_back(hardDiskSpace[i]);
mp[hardDiskSpace[i]]++;
mnTemp = min(mnTemp, hardDiskSpace[i]);
minQueue.insert(hardDiskSpace[i]);
}
ans = *minQueue.begin();
for (int i = segmentLength; i < n; i++) {
int going = segment[0];
int coming = hardDiskSpace[i];
mp[going]--, mp[coming]++;
minQueue.erase(going);
minQueue.insert(coming);
segment.erase(segment.begin());
segment.push_back(coming);
ans = max(ans, *minQueue.begin());
}
return ans;
}
Explanation:
Sliding Window Principle. O(n log n) Time Complexity
Asked By: Amazon US, Canada and India.