PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Coinbase
  • Coding & Algorithms
  • Software Engineer

Parse logs and generate NFT attributes

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given two independent coding tasks. ## Task 1: Parse and group a log file by thread ID You are given a list of log lines (strings). Each line contains at least: - a **timestamp** (parseable and comparable; assume ISO-8601 or an integer epoch), - a **thread ID** (integer or string), - an arbitrary **message**. Example format (you may assume a consistent format across all lines): - `2026-02-13T10:15:30Z thread=42 msg=Starting work` ### Requirements 1. Parse each line to extract `(timestamp, threadId, message)`. 2. Group logs by `threadId`. 3. For each `threadId`, sort that thread’s log entries by **timestamp ascending**. 4. Return a structure like `Map<threadId, List<LogEntry>>` (or `Map<threadId, List<String>>` preserving original lines) where each list is time-sorted. ### Edge cases to handle - Multiple logs with the same timestamp. - Malformed lines (state and apply a reasonable policy: skip, throw, or collect errors). --- ## Task 2: Generate NFT attribute combinations (and follow-ups) 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"]` ### Part A: Enumerate all combinations Generate **all possible NFTs** as combinations of choosing exactly one value from each category (i.e., the Cartesian product). Return the list of combinations. ### Follow-up 1: Deduplication 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. ### Follow-up 2: Weighted/random generation 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.

Quick Answer: 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.

Part 1: Parse and Group Log Lines by Thread ID

You are given a list of log lines. Each well-formed line has the exact format: '<timestamp> thread=<threadId> msg=<message>'. The timestamp has no spaces and is either an integer epoch string or an ISO-8601-like string that can be compared lexicographically. The message may contain spaces. Parse all well-formed lines, group them by thread ID, and sort each thread's log lines by timestamp ascending. If two lines for the same thread have the same timestamp, keep their original input order. Malformed lines must be skipped.

Constraints

  • 0 <= len(log_lines) <= 100000
  • Each log line has length at most 1000
  • A well-formed line is exactly '<timestamp> thread=<threadId> msg=<message>'
  • threadId is non-empty
  • Malformed lines are skipped
  • Timestamps are consistent in format across valid input lines

Examples

Input: (['2026-02-13T10:15:30Z thread=42 msg=Starting work', '2026-02-13T10:15:28Z thread=7 msg=Init', '2026-02-13T10:15:29Z thread=42 msg=Loading'],)

Expected Output: {'42': ['2026-02-13T10:15:29Z thread=42 msg=Loading', '2026-02-13T10:15:30Z thread=42 msg=Starting work'], '7': ['2026-02-13T10:15:28Z thread=7 msg=Init']}

Explanation: Logs are grouped by thread ID. Thread 42 has two entries sorted by timestamp.

Input: (['100 thread=A msg=first at 100', '99 thread=A msg=before', '100 thread=A msg=second at 100'],)

Expected Output: {'A': ['99 thread=A msg=before', '100 thread=A msg=first at 100', '100 thread=A msg=second at 100']}

Explanation: Integer timestamps are sorted numerically. The two timestamp-100 logs keep their input order.

Input: (['10 thread=1 msg=ok', 'bad line', '11 thread=2 nope', '9 thread=1 msg=old', '12 thread= msg=missing id'],)

Expected Output: {'1': ['9 thread=1 msg=old', '10 thread=1 msg=ok']}

Explanation: Malformed lines are skipped, including missing msg= and empty thread ID.

Input: ([],)

Expected Output: {}

Explanation: An empty input produces an empty grouping.

Hints

  1. Split each line into at most three pieces so the message can still contain spaces.
  2. Store the original index along with each parsed line to preserve order when timestamps tie.

Part 2: Generate All NFT Attribute Combinations

You are given NFT attribute categories and the possible values for each category. Generate every possible NFT by choosing exactly one value from each category. The output should list combinations as arrays of chosen values aligned with the input category order. The first category should change slowest, and the last category should change fastest.

Constraints

  • 0 <= len(categories) <= 12
  • len(categories) == len(values)
  • 0 <= len(values[i]) <= 100
  • Within this problem, values in each category are assumed to be distinct
  • The total number of generated combinations will not exceed 100000

Examples

Input: (['Background', 'Ears', 'Hat'], [['Red', 'Blue'], ['Pointy', 'Wide'], ['Cap', 'None']])

Expected Output: [['Red', 'Pointy', 'Cap'], ['Red', 'Pointy', 'None'], ['Red', 'Wide', 'Cap'], ['Red', 'Wide', 'None'], ['Blue', 'Pointy', 'Cap'], ['Blue', 'Pointy', 'None'], ['Blue', 'Wide', 'Cap'], ['Blue', 'Wide', 'None']]

Explanation: There are 2 * 2 * 2 = 8 possible NFTs.

Input: (['Hat'], [['Cap', 'None']])

Expected Output: [['Cap'], ['None']]

Explanation: With one category, each value forms one combination.

Input: ([], [])

Expected Output: [[]]

Explanation: The Cartesian product of zero categories contains one empty combination.

Input: (['Background', 'Hat'], [['Red'], []])

Expected Output: []

Explanation: If any category has no available values, no complete NFT can be formed.

Hints

  1. This is the Cartesian product of the value lists.
  2. Build combinations category by category by appending each possible value to existing partial combinations.

Part 3: Generate Unique NFT Attribute Combinations

You are given NFT attribute categories and possible values for each category. Some value lists may contain duplicates. Generate all unique NFT combinations by choosing exactly one value from each category. Combinations are represented as arrays of chosen values aligned with category order. Preserve deterministic order by considering each category's unique values in their first-occurrence order.

Constraints

  • 0 <= len(categories) <= 12
  • len(categories) == len(values)
  • 0 <= len(values[i]) <= 1000
  • Values are strings
  • The total number of unique generated combinations will not exceed 100000

Examples

Input: (['Background', 'Ears'], [['Red', 'Red', 'Blue'], ['Pointy', 'Pointy']])

Expected Output: [['Red', 'Pointy'], ['Blue', 'Pointy']]

Explanation: Duplicate Red and Pointy entries do not create duplicate NFTs.

Input: (['A', 'B'], [['x', 'x'], ['y', 'z', 'y']])

Expected Output: [['x', 'y'], ['x', 'z']]

Explanation: The unique values are A: x and B: y, z.

Input: (['Hat'], [['Cap', 'Cap', 'Cap']])

Expected Output: [['Cap']]

Explanation: All duplicate paths produce the same single combination.

Input: ([], [])

Expected Output: [[]]

Explanation: With no categories, there is one empty unique combination.

Input: (['A'], [[]])

Expected Output: []

Explanation: A category with no values makes it impossible to form an NFT.

Hints

  1. Duplicates inside one category can create duplicate final combinations.
  2. Deduplicate each category's value list while preserving first occurrence, then take the Cartesian product.

Part 4: Weighted NFT Generation with Optional Duplicate Avoidance

You are given NFT categories, possible values for each category, and a positive weight for each value. To make testing deterministic, you are also given a flat list of random numbers in [0, 1). Each generated NFT consumes one random number per category and samples one value from each category according to its weights. Generate up to count NFTs. If avoid_duplicates is true, skip any generated NFT that has already been accepted and keep consuming random numbers until count unique NFTs are accepted or there are not enough random numbers for another full attempt.

Constraints

  • 0 <= len(categories) <= 20
  • len(categories) == len(values) == len(weights)
  • len(values[i]) == len(weights[i])
  • Each non-empty category has total weight > 0
  • Weights are non-negative numbers
  • 0 <= random_numbers[i] < 1
  • 0 <= count <= 100000

Examples

Input: (['Background', 'Eyes'], [['Blue', 'Red'], ['Open', 'Closed']], [[1, 3], [2, 2]], [0.0, 0.49, 0.25, 0.99], 2, False)

Expected Output: [['Blue', 'Open'], ['Red', 'Closed']]

Explanation: The first attempt chooses Blue then Open. The second attempt uses the next two random numbers; 0.25 lands exactly on the first category boundary, so strict greater-than selects Red, and 0.99 selects Closed.

Input: (['Type'], [['A', 'B']], [[1, 1]], [0.1, 0.1, 0.9], 3, False)

Expected Output: [['A'], ['A'], ['B']]

Explanation: Duplicates are allowed, so the two generated A NFTs are both accepted before B is generated.

Input: (['Type'], [['A', 'B']], [[1, 1]], [0.1, 0.1, 0.9, 0.2], 3, True)

Expected Output: [['A'], ['B']]

Explanation: The second A and final A are duplicates and are skipped. Only A and B are accepted before random numbers run out.

Input: (['Color', 'Shape'], [['Red', 'Blue'], ['Circle', 'Square']], [[1, 1], [1, 1]], [0.1, 0.1, 0.2, 0.3, 0.8, 0.1, 0.8, 0.9], 3, True)

Expected Output: [['Red', 'Circle'], ['Blue', 'Circle'], ['Blue', 'Square']]

Explanation: The second generated NFT is another Red-Circle, so it is skipped. Later unique NFTs are accepted until count reaches 3.

Input: ([], [], [], [], 3, True)

Expected Output: [[]]

Explanation: With no categories, the only possible unique NFT is the empty NFT. Duplicate avoidance allows it once.

Input: (['A', 'B', 'C'], [['x', 'y'], ['p', 'q'], ['m', 'n']], [[1, 1], [1, 1], [1, 1]], [0.6, 0.4, 0.9, 0.1, 0.2], 2, False)

Expected Output: [['y', 'p', 'n']]

Explanation: One full attempt needs 3 random numbers. After accepting the first NFT, only 2 random numbers remain, so generation stops.

Input: (['Type'], [['A', 'B']], [[1, 1]], [0.1, 0.9], 0, True)

Expected Output: []

Explanation: When count is 0, no NFTs should be generated.

Hints

  1. Convert each category's weights into prefix sums. A random number r selects the first prefix sum greater than r * total_weight.
  2. When avoiding duplicates, store accepted combinations as tuples in a set.
Last updated: Jun 17, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement a Coin-Constrained Jump Strategy - Coinbase (hard)
  • Implement an In-Memory Database - Coinbase (hard)
  • Implement Game Physics and Block Mining - Coinbase (hard)
  • Compute Total Manual Distance - Coinbase (medium)
  • Implement a Flappy Bird Jump Agent - Coinbase