Jump Trading logoJump Trading
CodingFree preview

File Sync Comparison (Source vs. Destination Listings)

Given space-delimited listings (permissions, username, size, modification time, filename) for a source and a destination, return the filenames that must be synced, in source order. The canonical example implies: sync when the file is missing at the destination or when size or modification time differ; skip when the destination copy is not writable or the source copy is not readable. A related variant parses {owner, permission, filename} lines and reports which files are read-only.

SWE
string-processing
parsing
filesystem
easy
Frequency
Medium
Last asked
2026-08-22
Stage
oa

Problem

Given a list of source_files and a list of destination_files, return the filenames that need to be synced from source to destination, in the order they appear in source_files.

Each element is a string with 5 space-delimited columns, left to right:

  1. permissioning (e.g. rwx, r-x, -wx)
  2. username
  3. size
  4. modification time (hh:mm:ss)
  5. filename

Examples

Source:

["rwx alex 2673422 05:04:03 somefilename.txt", "rwx alice 993432 05:45:00 myfile.csv", "rwx alex 734673422 19:24:13 foobar.txt", "-wx root 184 12:04:05 barfoo.txt", "r-- alice 10 02:00:00 helloworld.txt"]

Destination:

["rwx alex 5 05:04:03 somefilename.txt", "rwx alice 993432 10:45:00 myfile.csv", "r-x alex 734673422 04:24:13 foobar.txt", "rwx root 4 12:04:05 barfoo.txt"]

Expected output:

["somefilename.txt", "myfile.csv", "helloworld.txt"]
  • somefilename.txt — sizes differ between source and destination.
  • foobar.txt — not writable at the destination, so it is not synced.

Rules implied by the example

The statement only explains two of the five files; the rest of the expected output pins down the remaining rules:

  • myfile.csv — same size, different modification time → synced (even though the destination copy is the newer one).
  • barfoo.txt — sizes differ, but the source copy is -wx (not readable) → not synced.
  • helloworld.txt — absent from the destination → synced.

Variants

Read-only file query

A shorter Codility variant gives lines of {owner, permission, filename} and asks which files are read-only. Same parsing skeleton; the decision is a single permission check instead of a source/destination comparison.

Pitfalls

  • The written explanation ends with "etc." — derive every rule from the expected output and confirm it before coding rather than stopping at the two stated reasons.
  • Modification time differences trigger a sync in both directions; do not add a "only if source is newer" condition.
  • Permission checks apply to different sides: readability on the source, writability on the destination.
  • Preserve source order in the result; do not iterate the destination map.

Preparation

  • Implement the parser and decision function, then run it against the example above and check each of the five files against the rule list.
  • Write extra test lines for each rule in isolation (missing file, size-only diff, time-only diff, unwritable destination, unreadable source).
  • Implement the read-only variant on the same parser in under 10 minutes.
Was this article helpful?

Comments

Sign in to join the discussion
Loading...