Your question is Last Man Standing Stream. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Zillow processes a circular stream of listing IDs for a controlled rotation. Starting at the first listing, count step remaining listings, remove the counted listing, and continue counting from the next remaining listing. Return the listing ID that remains last.
Avoid simulating removals with repeated list deletion, since the input can be large. Derive and implement an efficient solution based on the Josephus recurrence.
Implement last_remaining(listing_ids, step).
listing_ids is a non-empty list of distinct integers in stream order.step is a positive integer.0, and the first removed listing is the stepth listing, wrapping around as necessary.def last_remaining(listing_ids, step):