Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,385 views

All interview experiences for Google  can be found using the tag "google_interview_experiences" in the search bar.

Here is the link : https://www.desiqna.in/tag/google_interview_experiences

in Interview-Experiences by Expert (35,210 points) | 1,385 views

1 Answer

0 like 0 dislike

Problem Statement:
You are given a distance d and a stream of float numbers (i.e., numbers are given one at a time). Your task is to write a method that takes this number as an input, and checks for a group of three numbers, where each number is within a distance 'd' of other two.
If found, remove them from your collection and return.

 

Lets say for a group of 3 numbers found, a, b and c, the following condition holds:

 

|a - b| <= d and |b - c| <= d and |c - a| <= d

 

Example:
for a distance d = 1,
input = 1.1, action => None
input = 2.1, action => None
input = 3.1, action => None
input = 1.5, action => Remove and return {1.1, 2.1, 1.5} as an output.

 

Clarifying questions that I remember asking:

 

  • Is d inclusive for distance between two number? -> Yes
  • What if the new number received leads to formation of multiple such triplets? -> We decided that smallest three numbers we would remove.
  • Any desired order of output values? -> No.

 

by Expert (35,210 points)

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .