This paired question evaluates array and algorithmic skills — specifically order-statistics and missing-number reasoning for the k-th missing positive, and time-window aggregation with frequency tracking for detecting redundant log events — within the coding & algorithms domain.
You are given two independent coding tasks.
You are given an integer array nums (not necessarily sorted) containing distinct positive integers, and an integer k.
Define the missing numbers as the positive integers that do not appear in nums.
Return the k-th smallest missing positive integer.
Constraints (representative of an “optimal required” setting):
1 <= n <= 2e5
1 <= nums[i] <= 1e9
(distinct)
1 <= k <= 1e9
Example:
nums = [2, 3, 7, 11], k = 5
1, 4, 5, 6, 8, 9, 10, 12, ...
8
You are given two arrays of equal length ops[] and times[] describing a log of events, where:
ops[i]
is a string operation name (e.g.,
"login"
,
"refresh"
)
times[i]
is the event time as an integer timestamp (seconds)
You are also given an integer window size W (seconds).
An event at index i is considered redundant if there exist two earlier events j < k < i such that:
ops[j] == ops[k] == ops[i]
times[i] - times[j] <= W
(i.e., 3 occurrences of the same operation happen within a
W
-second window ending at
times[i]
)
Return the total number of redundant events in the log.
Assumptions/notes:
Example:
ops = ["A","B","A","A","A"], times = [1,2,3,4,10], W = 5
4
is redundant because
A
occurred at times
1,3,4
within 5 seconds.
10
is
not
redundant for window
W=5
.
1