This question evaluates parsing and log-processing skills alongside combinatorics and weighted-sampling competency, covering extraction and time-based grouping of timestamped records, handling malformed input policies, enumeration of Cartesian products, deduplication, and probabilistic generation.
You are given two independent coding tasks.
You are given a list of log lines (strings). Each line contains at least:
Example format (you may assume a consistent format across all lines):
2026-02-13T10:15:30Z thread=42 msg=Starting work
(timestamp, threadId, message)
.
threadId
.
threadId
, sort that thread’s log entries by
timestamp ascending
.
Map<threadId, List<LogEntry>>
(or
Map<threadId, List<String>>
preserving original lines) where each list is time-sorted.
You are given a set of NFT attributes, where each attribute category has a list of possible values.
Example input:
Background: ["Red", "Blue"]
Ears: ["Pointy", "Wide"]
Hat: ["Cap", "None"]
Generate all possible NFTs as combinations of choosing exactly one value from each category (i.e., the Cartesian product). Return the list of combinations.
If the input may contain duplicates (e.g., Ears: ["Pointy", "Pointy", "Wide"]) or different paths could create the same final combination, ensure the output contains unique combinations only.
Now assume each value has an associated weight/probability (not necessarily uniform). Example:
Ears: Pointy=0.6, Wide=0.4
Design an algorithm to randomly generate an NFT (one combination) according to the specified weights per attribute category. Explain how you would implement the sampling step efficiently and how (if required) you would handle avoiding duplicates when generating many NFTs.