Problemfile backup system

Session: Sign in to solve

Solution.txt

File Backup System

Problem

Design FileBackupSystem to apply batches of file writes to persistent current state and return the entries captured by a chosen backup policy.

Requirements

  • Apply writes in order. Before producing output, each call applies its supplied FileWrite objects in list order. A later write to the same file replaces its earlier content.
  • Keep current state. Current file content persists across calls, including calls with another backup type or an empty writes list.
  • Capture full state. FULL returns exactly one entry for every current file after applying the supplied writes.
  • Start with an empty baseline. The latest-full baseline is empty before the first FULL call.
  • Replace the full baseline. After applying its writes, each FULL call replaces the baseline with the complete resulting current state.
  • Preserve the full baseline. DIFFERENTIAL and LOG calls leave the latest-full baseline unchanged.
  • Capture differences. DIFFERENTIAL returns exactly one final entry for every current file whose content differs from the latest-full baseline after applying the supplied writes.
  • Capture the write log. LOG returns one entry for each supplied write in the same order, including repeated writes to one file.

API

FileWrite and BackupEntry are objects with string fields fileName and content.

SignatureReturnsBehavior
FileBackupSystem()Not applicableCreates a system with empty current state and an empty latest-full baseline.
createBackup(backupType: string, writes: list<FileWrite>)list<BackupEntry>Applies the writes and returns entries for FULL, DIFFERENTIAL, or LOG. Only inputs satisfying the constraints are judged.

Full and differential entries have no required order. Log entries preserve the supplied write order.

Examples

Start with a new system.

StepOperationResult
1createBackup("DIFFERENTIAL", [{fileName: "a.txt", content: "A1"}])[{fileName: "a.txt", content: "A1"}]
2createBackup("FULL", [])[{fileName: "a.txt", content: "A1"}]
3createBackup("DIFFERENTIAL", [{fileName: "a.txt", content: "A2"}])[{fileName: "a.txt", content: "A2"}]
4createBackup("DIFFERENTIAL", [{fileName: "a.txt", content: "A1"}])[]
5createBackup("LOG", [{fileName: "x", content: "1"}, {fileName: "x", content: "2"}])[{fileName: "x", content: "1"}, {fileName: "x", content: "2"}]

Constraints

  • backupType is FULL, DIFFERENTIAL, or LOG.
  • Each writes list contains at most 10,000 objects.
  • File names contain from 1 through 100 Unicode scalar values.
  • File content contains at most 1,000 Unicode scalar values and may be empty.
  • A Unicode scalar value is a Unicode code point other than a surrogate code point.
  • At most 10,000 distinct file names, 100,000 total writes, and 10,000 calls occur in one testcase.
  • Files cannot be deleted.

Notes

Calls are sequential on one system and take effect in invocation order. createBackup does not wait for an external event.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.