aklepatc ([personal profile] aklepatc) wrote2024-05-08 01:34 pm

Strange Container

Code a data structure with 2 operations: push() and popMostFrequent().

Most of the meat is in the comments/discussion below.

[personal profile] sassa_nf 2024-05-09 04:34 pm (UTC)(link)
Well, it is surprising to those familiar with java byte buffers. Slicing a buffer there creates a slice of the underlying buffer, but does not share its limit - can't go beyond the last byte available in the buffer at the time of slicing, even if the capacity allows for that.

So to speak, cap(n)==len(n) immediately after slicing.