FastPrepCount Redundant File Backups

Count Redundant File Backups

Goldman Sachs logoGoldman Sachs● MediumINTERNOA
Learn

Problem statement

You are given two parallel arrays, fileName and timestamp. Record i describes a backup of file fileName[i] at time timestamp[i], measured in seconds. Records may arrive in any order.

A file is redundant if it has at least three backup records within some continuous 24-hour period. Equivalently, there must be three records for that file whose largest timestamp minus their smallest timestamp is at most 86,400.

Return the number of distinct redundant files. Count each file once, even when several qualifying periods exist. A period may start at any time; it is not restricted to calendar-day boundaries.

For this exercise, compare filenames exactly, including letter case. Each array entry is a separate backup record, so repeated records and equal timestamps count separately.

Function

countRedundantFiles(fileName: String[], timestamp: int[]) → int

Examples

Example 1

fileName = ["sales","design","design","sales","sales"]timestamp = [47210,18902,73455,82960,24896]return = 1

The sales timestamps are 24896, 47210, and 82960. Their span is 58064 seconds, so sales is redundant. The design file has only two backup records.

Example 2

fileName = ["alpha","gamma","alpha","alpha"]timestamp = [32768,1296,96480,10080]return = 1

The alpha timestamps are 10080, 32768, and 96480. Their span is exactly 86400 seconds, which is allowed. The gamma file has only one record.

Example 3

fileName = ["log","log","log","log"]timestamp = [1,86402,172803,172804]return = 0

The first consecutive triple spans 172802 seconds, and the last spans 86402 seconds. Neither fits in 86400 seconds, so having four total backups is not sufficient.

Constraints

  • n == fileName.length == timestamp.length
  • 1 <= n <= 200000
  • 1 <= fileName[i].length <= 10
  • 1 <= timestamp[i] <= 1000000000

More Goldman Sachs problems

See Goldman Sachs hiring insights
public int countRedundantFiles(String[] fileName, int[] timestamp) {
    // Write your code here.
    return 0;
}
fileName["sales","design","design","sales","sales"]
timestamp[47210,18902,73455,82960,24896]
expected1
Checking account…