I came across this interesting Scala problem and not sure how to solve it:
class TopN {
def findTopN(n: Int)(stream: Stream[Int]): List[Int] = {
???
}
}
This is a test of abstract data engineering skills.
The function findTopN(...) in TopN is supposed to find the top N highest unique integers in a presumed endless stream of integers. To process the Stream of Int, you can only hold a few values in memory at a given time. Therefore, a memory efficient way to process this list is required.
Edit: Because it's an endless stream I understand the question as what are the top N numbers so far. So you have to maintain in-memory state.