#K78717. Duplicate Photo Finder in a Photo Library

    ID: 35149 Type: Default 1000ms 256MiB

Duplicate Photo Finder in a Photo Library

Duplicate Photo Finder in a Photo Library

In this problem, you are given a photo library represented as a nested JSON object. The outer object has years as keys, and its values are objects with months as keys. Each month key maps to a list of photo filenames.

Your task is to identify all photo filenames that appear in at least two different months (i.e. duplicates across the library). Note that if the same filename appears more than once in a single month, it should be counted only once for that month.

The answer should be printed as a JSON array of strings, containing the duplicate filenames sorted in alphabetical order.

For example, given the library:

{
  "2020": {
    "01": ["img1.jpg", "img2.jpg", "img3.jpg"],
    "02": ["img2.jpg", "img4.jpg"],
    "03": ["img3.jpg", "img5.jpg"]
  },
  "2021": {
    "01": ["img6.jpg", "img2.jpg"],
    "04": ["img1.jpg", "img7.jpg"]
  }
}

the duplicate filenames are ["img1.jpg", "img2.jpg", "img3.jpg"].

inputFormat

The input is given as a single JSON object from standard input (stdin) representing the photo library. The object keys are years (strings) and their values are JSON objects with month keys and lists of photo filenames as values.

Example:

{
  "2020": {
    "01": ["img1.jpg", "img2.jpg", "img3.jpg"],
    "02": ["img2.jpg", "img4.jpg"],
    "03": ["img3.jpg", "img5.jpg"]
  },
  "2021": {
    "01": ["img6.jpg", "img2.jpg"],
    "04": ["img1.jpg", "img7.jpg"]
  }
}

outputFormat

Output a JSON array (to stdout) containing the duplicate photo filenames, sorted in alphabetical order. If there are no duplicates, output an empty array.

Example Output:

["img1.jpg", "img2.jpg", "img3.jpg"]
## sample
{"2020": {"01": ["img1.jpg", "img2.jpg"], "02": ["img3.jpg", "img4.jpg"]}, "2021": {"03": ["img5.jpg", "img6.jpg"]}}
[]