This problem teaches the technique of maintaining auxiliary state alongside a primary data structure — a pattern used in many design problems.
Enable JavaScript for the full StreamPrep guide.