Q: There is stream of float values (-inf, inf) which is coming as input and an integer D.
We need to find a set of 3 values which satisfy condition - |a - b| <= D, |b - c| <= D, |a - c| <= D, assuming a,b,c are 3 float values. Print these 3 values and remove them and continue ....
Constraints -
All values in stream will be unique.
D -> [0, inf)
Eg:
Input stream - [1,10,7,-2,8,....], d = 5
Output - (when 8 comes, then print "7 8 10" and remove them and continue)
class Solution {
private int D;
void init(int d) {
this.D = d;
void func(float item) {
// implement
}
}What data structure should be used here, and what approach can be applied?