google Onsite Round 1 Question
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-04-29Added By Anonymous
Source: Link
🧭 Experience: unknown
✅ Outcome: unknown
💰 Compensation: unknown
📍 Location: unknown
🏢 Company: Google
🎓 Education: unknown
🎁 Benefits: unknown
📅 Offer Date: unknown
completed my google onsite interview and here is the question
we will be getting stream of floating point numbers one at time and we will be getting distance d at the beginning..
now we have to find the triplet(a,b,c) such that no two elements difference shoud not exceed the distace d and if we find the triplet we also need to remove the triplet form the storage also
and we have to fix the data strcuture and need to write the code scatch like class and functions
please rate this question before seeing the solution.
some thing like this is my approach
class StreamOfNumbersforTriplet{
TreeSet<Float> streamOfValues;
float distanceToCheck;
StreamOfNumbersforTriplet(float distanceToCheck){
streamOfValues = new HashSet<>();
this.distanceToCheck = distanceToCheck;
}
void addFloatNumberToStream(float numberTobeAdded){
streamOfValues.add(numberTobeAdded);
if(streamOfValues.size()>=3){
System.out.println(validTriplet(streamOfValues));
}
}
Triplet validTriplet(TreeSet<Float> streamOfValues){
ArrayList<Float> currentList = streamOfValues.toList();
int initial =0;
int final = 2;
while(initial<streamOfValues.size()-2){
if(currentList.get(final)-currentList.get(initial)<=distanceToCheck){
float firstValue = currentList.get(first);
float secondValue = currentList.get(first+1);
float thirdValue = currentList.get(final);
streamOfValues.remove(firstValue);
streamOfValues.remove(secondValue);
streamOfValues.remove(thridValue);
return new Triplet(currentList.get(first), currentList.get(first+1), currentList.get(final));
}
intial += 1;
final += 1;
}
return new Triplet();
}
}
class Triplet{
float firstValue;
float secondValue;
float thirdValue;
Triplet(){
System.out.println("no Valid triplet Found");
}
Triplet(float firstValue, foat secondValue, float thirdValue){
this.firstValue = firstValue;
this.secondValue = secondValue;
this.thirdValue = thirdValue;
}
}
and said the time and space complexity for each insert is O(N) i said
interviewer not pasted the question instead she just explained the question and i am not able to understand as she is not sure about the question and corrected the actual question in the middle and at the end of the interview i have asked what will guve me feedback and she said you good at problem solving and keep asking more questions,
not sure what will i get like hire or no hire please let me know in the comments , and also please rate this question.
Thanks.