Analyze document collaboration patterns
You are provided with two CSV files containing document activity and user information, and your task is to analyze collaboration patterns.
Data Files
document_activity.csv
Each row represents a document view event.
page_id(STRING): Unique document identifier.user_id(STRING): Identifier of the user who viewed the document.viewed_at(TIMESTAMP): The UTC timestamp of the view event.is_creator(BOOLEAN):trueif the user is the document creator,falseotherwise.collaborator_source(STRING NULL): For non-creators, this indicates how the user accessed the document (e.g., invite link, email invite, search, direct). This field may beNULLfor creators.
users.csv
user_id(STRING): Unique user identifier.country(STRING): The country of the user.
Assumptions
- The join key between
document_activityanduserstables isuser_id. - All available data should be used; no date filtering is required.
- For collaboration-related questions, unless explicitly stated otherwise, deduplicate to distinct
(page_id, user_id)pairs to count unique user-document interactions, not individual view events. - A document can have one creator and multiple collaborators.
Tasks
-
Compute the distribution of collaborator acquisition sources.
- Focus only on non-creators (
is_creator = false). - The metric should be based on distinct collaborator-document pairs
(page_id, user_id). - Required output columns:
collaborator_sourcecollaborator_countcollaborator_share
- Focus only on non-creators (
-
Given an input
user_id, find which other users collaborated with that user the most.- Two users are considered collaborators if they have both appeared on the same
page_idat least once. - Count distinct shared documents, not view events.
- Exclude the target user themselves from the results.
- Required output columns:
target_user_idco_user_idshared_page_count
- Return the user(s) with the maximum
shared_page_count.
- Two users are considered collaborators if they have both appeared on the same
-
Find which country's users are most likely to collaborate with others.
- A user is defined as having "collaborated with others" if they appear on at least one document with at least one other distinct user (i.e., the document has 2 or more distinct users total).
- For each country, compute the following metrics:
collaborating_users: The number of distinct users in that country who collaborated with at least one other user.total_users: The total number of distinct users in that country, sourced fromusers.csv.collaboration_rate: Calculated ascollaborating_users / total_users.
- Required output columns:
countrycollaborating_userstotal_userscollaboration_rate
- Rank countries from highest to lowest collaboration rate.
AI interview prep
Core dilemma
Accurately defining and calculating complex collaboration metrics across multiple tables while ensuring data integrity, handling edge cases (like self-collaboration, creator status, null values), and optimizing for potentially large datasets. It's about translating nuanced business logic into precise and efficient data queries.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Analyze document collaboration patterns
You are provided with two CSV files containing document activity and user information, and your task is to analyze collaboration patterns.
Data Files
document_activity.csv
Each row represents a document view event.
page_id(STRING): Unique document identifier.user_id(STRING): Identifier of the user who viewed the document.viewed_at(TIMESTAMP): The UTC timestamp of the view event.is_creator(BOOLEAN):trueif the user is the document creator,falseotherwise.collaborator_source(STRING NULL): For non-creators, this indicates how the user accessed the document (e.g., invite link, email invite, search, direct). This field may beNULLfor creators.
users.csv
user_id(STRING): Unique user identifier.country(STRING): The country of the user.
Assumptions
- The join key between
document_activityanduserstables isuser_id. - All available data should be used; no date filtering is required.
- For collaboration-related questions, unless explicitly stated otherwise, deduplicate to distinct
(page_id, user_id)pairs to count unique user-document interactions, not individual view events. - A document can have one creator and multiple collaborators.
Tasks
-
Compute the distribution of collaborator acquisition sources.
- Focus only on non-creators (
is_creator = false). - The metric should be based on distinct collaborator-document pairs
(page_id, user_id). - Required output columns:
collaborator_sourcecollaborator_countcollaborator_share
- Focus only on non-creators (
-
Given an input
user_id, find which other users collaborated with that user the most.- Two users are considered collaborators if they have both appeared on the same
page_idat least once. - Count distinct shared documents, not view events.
- Exclude the target user themselves from the results.
- Required output columns:
target_user_idco_user_idshared_page_count
- Return the user(s) with the maximum
shared_page_count.
- Two users are considered collaborators if they have both appeared on the same
-
Find which country's users are most likely to collaborate with others.
- A user is defined as having "collaborated with others" if they appear on at least one document with at least one other distinct user (i.e., the document has 2 or more distinct users total).
- For each country, compute the following metrics:
collaborating_users: The number of distinct users in that country who collaborated with at least one other user.total_users: The total number of distinct users in that country, sourced fromusers.csv.collaboration_rate: Calculated ascollaborating_users / total_users.
- Required output columns:
countrycollaborating_userstotal_userscollaboration_rate
- Rank countries from highest to lowest collaboration rate.