abhi10901
BAN USER- -1of 1 vote
AnswersGiven a stream of objects, O1, O2, O1, O3, O4... Provide an algorithm to identify the first unique object at any given point in time.
- abhi10901 in United States for AWS Auto Scaling
So for example, in the above, after receiving the first Object, it is unique. After receiving the second, the first is still the first unique object. After receiving the 3rd, the 1st object is no longer unique (you've not seen O1 twice), so O2 is not the first unique object. etc...| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm
Java Solution
public static void editArray(int[] arr, int m) {
int curElm = 0, curIndx = 0, count = 0;
for(int i = 0; i < arr.length; i++) {
if(curElm == arr[i]) {
count++;
} else count = 1;
if(count <= Math.min(2, m)) {
arr[curIndx] = arr[i];
curElm = arr[i];
curIndx++;
}
}
while(curIndx < arr.length) {
arr[curIndx] = 0;
curIndx++;
}
}
RepDo you Need Voodoo Spell For love, revenge or voodoo spells for cheaters? Consult Free right away to get custom ...
RepElenaKudaeva455, Music Piano Store at xyz
Hello Everyone,My name is Elena Kudaeva From NV,Nevada,USA.I am 16 years of age and I have ...
Repstanjachrissi, Integration Software Engineer at xyz
Hi,my name is Stanja Chrissi. I was conceived and FL. I moved on from CA and went ahead to ...
Repadorasherlyn253, SEO
I am a professor, I have 5 years of experience. I have seen a lot of cases in my life ...
RepEdwin Adcox, Dev Lead at Advisory Board Company
Welcome to the best and certified exotic car rental company of USA. Here, at Prestige luxury Rentals, we offer the ...
RepRocioNavarro189, None at Student
Hello Everyone,My name is Rocio Navarro Form Auckland,NZ,and 31 years old.I am searching for a servant ...
RepGerard Swearingen, Consultant at ADP
Want to book exotic and luxury car rental in Atlanta, GA ? We, Prestige Luxury Rentals are the best car rentals ...
I'll create this data structure using two Stacks.
- abhi10901 June 06, 20171) Regular Stack: Stores elements in the order they arrived on top of the stack
2) Minimum Stack: Stores only elements which are less than or equal to the current top of the same stack.
Functions:
1) AddElement:
Push element on top of the regular stack
Push element on top of the minimum stack only when stack is empty or element is less or equal to the element on top of the stack
2) GetLastElement:
Peek element from the top of the regular stack
3) RemoveLastElement:
Pop element from the top of the regular stack
Pop element from the top of the minimum stack only when stack is not empty and the element on top of the stack is equal to the popped element from regular stack
4) GetMin:
Peek element from the top of the minimum stack
All operations are O(1) time complexity.