This multi-part question evaluates set and multiset operations, frequency counting, top-K computation over time windows, sliding-window and streaming data structures, and character-multiset matching for string construction within the coding & algorithms domain.
You are given two integer arrays A and B that represent sets, except they may contain duplicates and are not sorted.
Return true if they represent the same mathematical set (same unique elements), otherwise return false.
Example
A = [1,2,2,3]
,
B = [3,1,2]
→
true
A = [1,2]
,
B = [1,2,4]
→
false
Constraints
0 <= len(A), len(B) <= 2e5
You are given an impression log as a list of events:
events[i] = (timestamp_ms, ad_id)
events
is sorted by
timestamp_ms
ascending.
Part 1 (batch): Given events, a window size W_ms, and an end time T_end, return the top K ad IDs by number of impressions whose timestamps fall in [T_end - W_ms, T_end].
Break ties by smaller ad_id (or specify a deterministic rule).
Part 2 (streaming): Implement a data structure with two operations:
ingestImpression(timestamp_ms, ad_id)
getTopK(T_end, W_ms, K)
such that it efficiently supports a sliding window query over recent impressions.
Assume ingestImpression timestamps are non-decreasing.
Given two strings source and target, determine if you can form target using characters from source.
source
can be used
at most once
.
true
if possible, else
false
.
Example
source = "aab"
,
target = "aba"
→
true
source = "ab"
,
target = "abb"
→
false
Constraints
a-z
if you want to simplify).
2e5
.