← Questions
Evict old conversations to cap the distinct listings in context
0
I was asked this
No reports yet. Sign in to say where you were asked it.
An agent keeps a history of conversations, oldest first, and each conversation mentions some listing IDs (the same ID can show up in many conversations, or twice in one). To keep the context small, drop whole conversations from the oldest end until the remaining ones mention at most max_listings distinct IDs. Then return the distinct IDs that remain, in the order they first appear. Do it in one pass by keeping a count per ID, so an ID only stops counting once its last remaining mention is gone.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
