Identifying Customers with Visits but No Transactions
Many businesses track customer visits and transactions separately. This challenge focuses on identifying customers who visited a store or used a service but did not complete any purchases or transactions during that visit. This is valuable for targeted marketing campaigns (e.g., offering discounts to encourage future purchases) and understanding customer behavior.
Problem Description
You are given two datasets: a Visits dataset and a Transactions dataset. The Visits dataset records customer visits, and the Transactions dataset records customer transactions. Your task is to identify all customers who have a record in the Visits dataset but do not have a corresponding record in the Transactions dataset for the same visit. The visit is identified by a unique VisitID.
Key Requirements:
- You must identify customers who visited but did not transact.
- The solution should handle cases where a customer has multiple visits, some with transactions and some without.
- The output should be a list of
CustomerIDs representing customers who visited but did not transact.
Expected Behavior:
The solution should return a list of unique CustomerIDs. The order of the CustomerIDs in the output list is not important.
Edge Cases to Consider:
- Empty
Visitsdataset: Return an empty list. - Empty
Transactionsdataset: Return allCustomerIDs from theVisitsdataset. - A
VisitIDpresent in both datasets but with differentCustomerIDs (this should be treated as an error, but for simplicity, assume this won't happen in the input). - Duplicate
VisitIDs within either dataset (assume these are invalid and should be ignored - focus on uniqueVisitIDs).
Examples
Example 1:
Visits:
CustomerID | VisitID
---------- | --------
1 | A123
2 | B456
1 | C789
3 | D012
Transactions:
CustomerID | VisitID
---------- | --------
1 | A123
2 | B456
Output:
[1]
Explanation: Customer 1 visited with VisitID A123 and C789. They transacted with A123, but not C789. Customer 2 visited with B456 and transacted. Customer 3 visited with D012 and did not transact. Therefore, the output is [1].
Example 2:
Visits:
CustomerID | VisitID
---------- | --------
4 | E345
5 | F678
Transactions:
CustomerID | VisitID
---------- | --------
4 | E345
Output:
[5]
Explanation: Customer 4 visited with E345 and transacted. Customer 5 visited with F678 and did not transact. Therefore, the output is [5].
Example 3:
Visits:
CustomerID | VisitID
---------- | --------
6 | G901
6 | H234
7 | I567
Transactions:
CustomerID | VisitID
---------- | --------
6 | G901
Output:
[6, 7]
Explanation: Customer 6 visited with G901 and H234. They transacted with G901, but not H234. Customer 7 visited with I567 and did not transact. Therefore, the output is [6, 7].
Constraints
- The number of visits in the
Visitsdataset will be between 0 and 1000. - The number of transactions in the
Transactionsdataset will be between 0 and 1000. CustomerIDis an integer.VisitIDis a string.- The solution should have a time complexity of O(n + m), where n is the number of visits and m is the number of transactions. (This is a guideline, not a strict requirement, but efficient solutions are preferred).
Notes
Consider using a hash table (dictionary or map) to efficiently check for transactions associated with each visit. Focus on identifying unique CustomerIDs who have a visit record but no corresponding transaction record. The datasets are assumed to be clean (no invalid data types).