Checkpoint dirty pages

Write codeEasy14 minOracle and Snowflake style

Your task

A storage engine is taking a checkpoint. Its dirty page table holds one entry per change that sits in memory and not yet on disk, written as "p7|412": a page id, a pipe, then the log sequence number of that change. A page id can appear several times, and the number that matters for a page is the smallest one it carries, the oldest change it has not written out. The checkpoint writes every page whose smallest number is at most checkpoint_lsn. A written page costs page_bytes and afterwards carries nothing. Every other page stays dirty. Return three numbers in this order: how many pages were written, how many bytes those writes cost, and the restart point, which is the smallest number still carried by a page left dirty, or checkpoint_lsn when no page is left dirty.

Examples

checkpoint_flush_plan(dirty_pages: list[str], checkpoint_lsn: int, page_bytes: int) -> list[int]
Example 1
Inputcheckpoint_flush_plan(["p1|100", "p2|250", "p3|400"], 300, 8192)
Output[2, 16384, 400]
Example 2
Inputcheckpoint_flush_plan(["p4|900", "p4|120", "p5|950"], 500, 4096)
Output[1, 4096, 950]
Example 3
Inputcheckpoint_flush_plan(["p7|700", "p8|860"], 500, 4096)
Output[0, 0, 700]