Hone logo
Hone
Problems

Daily Leads and Partners

This challenge involves analyzing a dataset of sales activities to identify daily lead generation and partnership activities. You will be tasked with calculating the number of unique leads and partners acquired each day. This is a common task in sales analytics to understand the effectiveness of outreach strategies and partnership development.

Problem Description

You are given a dataset representing sales interactions. Each interaction record includes a date, an interaction_type (either 'lead' or 'partner'), and a customer_id. Your goal is to produce a report that shows, for each date, the total count of unique leads and the total count of unique partners acquired on that day.

Key Requirements:

  • Process a list of interaction records.
  • For each distinct date, count the unique customer_ids associated with 'lead' interactions.
  • For each distinct date, count the unique customer_ids associated with 'partner' interactions.
  • The output should group results by date.

Expected Behavior:

The output should be a collection of records, where each record represents a specific date and contains the count of unique leads and unique partners for that date. If a date has no leads or no partners, the corresponding count should be 0.

Important Edge Cases:

  • A customer might interact multiple times on the same day, but should only be counted once for leads or partners on that day.
  • A customer could be both a lead and a partner on the same day, but these should be counted separately in their respective categories.
  • The input data may not be sorted by date.
  • There might be dates with only leads, only partners, or neither.

Examples

Example 1:

Input:
[
  { "date": "2023-10-26", "interaction_type": "lead", "customer_id": "C001" },
  { "date": "2023-10-26", "interaction_type": "lead", "customer_id": "C002" },
  { "date": "2023-10-26", "interaction_type": "partner", "customer_id": "P001" },
  { "date": "2023-10-27", "interaction_type": "lead", "customer_id": "C001" },
  { "date": "2023-10-27", "interaction_type": "partner", "customer_id": "P002" },
  { "date": "2023-10-27", "interaction_type": "partner", "customer_id": "P003" }
]
Output:
[
  { "date": "2023-10-26", "unique_leads": 2, "unique_partners": 1 },
  { "date": "2023-10-27", "unique_leads": 1, "unique_partners": 2 }
]

Explanation: On "2023-10-26", customers "C001" and "C002" were leads (2 unique leads). Customer "P001" was a partner (1 unique partner). On "2023-10-27", customer "C001" was a lead (1 unique lead). Customers "P002" and "P003" were partners (2 unique partners).

Example 2:

Input:
[
  { "date": "2023-11-01", "interaction_type": "lead", "customer_id": "C101" },
  { "date": "2023-11-01", "interaction_type": "lead", "customer_id": "C101" },
  { "date": "2023-11-01", "interaction_type": "partner", "customer_id": "P101" },
  { "date": "2023-11-02", "interaction_type": "partner", "customer_id": "P102" },
  { "date": "2023-11-02", "interaction_type": "partner", "customer_id": "P102" }
]
Output:
[
  { "date": "2023-11-01", "unique_leads": 1, "unique_partners": 1 },
  { "date": "2023-11-02", "unique_leads": 0, "unique_partners": 1 }
]

Explanation: On "2023-11-01", although "C101" appears twice as a lead, it's only counted as 1 unique lead. "P101" is 1 unique partner. On "2023-11-02", there are no leads, so unique_leads is 0. "P102" appears twice as a partner, but is counted as 1 unique partner.

Example 3: (Edge Case - No interactions on a day)

Input:
[
  { "date": "2023-12-01", "interaction_type": "lead", "customer_id": "C201" }
]
Output:
[
  { "date": "2023-12-01", "unique_leads": 1, "unique_partners": 0 }
]

Explanation: On "2023-12-01", there's one lead ("C201") and no partners.

Constraints

  • The input will be a list of interaction objects, each containing date (string in YYYY-MM-DD format), interaction_type (string, either "lead" or "partner"), and customer_id (string).
  • The number of interaction records can range from 0 to 100,000.
  • The number of unique dates can range from 0 to 1,000.
  • The customer_id strings are alphanumeric and can be up to 50 characters long.
  • Your solution should aim for an efficient time complexity, ideally O(N) or O(N log N) where N is the number of interaction records.

Notes

  • You will need a way to store and aggregate counts for each day. Consider using data structures that allow for efficient lookups and updates.
  • Handling uniqueness is crucial. Think about how to efficiently track which customers have already been counted for a specific day and interaction type.
  • The output should include all dates that have at least one interaction, even if the count for one category is zero. If the input is empty, the output should also be empty.
Loading editor...
plaintext