E-commerce platforms frequently rank sellers to decide featured placements, promotions, and incentives.
This problem simulates a real-world backend/data scenario where seller performance is distributed across multiple months and must be evaluated using business rules.
๐ Problem Statement
An e-commerce platform wants to identify the Top 10 sellers for featured promotions based on their performance over the last 3 months.
๐ Data Sources
jan_orders.csvfeb_orders.csvmar_orders.csv
Each Record
(sellerId, orderValue, customerRating)
Each record represents one completed order.
✅ Selection Criteria
A seller is considered eligible only if all the following conditions are met:
At least 100 total orders across all months
Average customer rating ≥ 4.2
At least 20 orders in EACH month
Ranking Rule
Rank sellers by average order value
Select the Top 10 sellers
๐ฏ Expected Output
List<String> → sellerIds sorted by average order value (highest first)
๐ง Key Clarifications (Interview Gold)
Before coding, clarify these assumptions:
Customer rating is per order (not per seller)
Average rating =
totalRatings / totalOrdersAverage order value =
totalOrderValue / totalOrdersA seller missing even one month is not eligible
≥ 4.2means 4.2 is allowed
These clarifications show strong analytical thinking.
๐ High-Level Approach
Step 1: Aggregate seller data
Use a map:
sellerId → SellerSummary
Track:
order count per month
total order value
total rating sum
Step 2: Compute derived metrics
For each seller:
totalOrders
averageRating
averageOrderValue
Step 3: Apply eligibility rules
Filter sellers who fail any condition:
totalOrders < 100
any month < 20 orders
averageRating < 4.2
Step 4: Rank & select
Sort by average order value (DESC)
Pick top 10
๐งฉ Java Data Model (Interview-Ready)
class SellerSummary {
String sellerId;
int ordersJan, ordersFeb, ordersMar;
double totalOrderValue;
double totalRating;
int totalOrders() {
return ordersJan + ordersFeb + ordersMar;
}
double averageRating() {
return totalOrders() == 0 ? 0 : totalRating / totalOrders();
}
double averageOrderValue() {
return totalOrders() == 0 ? 0 : totalOrderValue / totalOrders();
}
boolean isEligible() {
return totalOrders() >= 100
&& ordersJan >= 20
&& ordersFeb >= 20
&& ordersMar >= 20
&& averageRating() >= 4.2;
}
}
๐ง Stream Pipeline (Conceptual)
sellers.values().stream()
.filter(SellerSummary::isEligible)
.sorted(Comparator.comparingDouble(
SellerSummary::averageOrderValue).reversed())
.limit(10)
.map(s -> s.sellerId)
.toList();
⏱ Time & Space Complexity
Let:
N= total number of ordersS= number of sellers
| Operation | Complexity |
|---|---|
| Aggregation | O(N) |
| Filtering | O(S) |
| Sorting | O(S log S) |
| Space | O(S) |
This is optimal and production-ready.
❌ Common Mistakes to Avoid
Always calculate from totals
Use
doublefor all averages
Ignoring monthly constraints
Each month must meet minimum orders
Using
>instead of≥Ratings are inclusive here
Ranking before filtering
Eligibility must come first
๐ How to Extend This in Real Systems
Support N months dynamically
Exclude canceled/returned orders
๐งช Interview Follow-Up Questions
How would you handle seller fraud or fake ratings?
What if promotions require category-wise top sellers?
How would you optimize this for millions of orders/day?
Would you precompute rankings or calculate on demand?
✅ Final Takeaway
This problem tests more than coding:
✔ data modeling
✔ aggregation logic
✔ business rule enforcement
✔ ranking correctness
✔ scalability thinking
If you can clearly explain this flow, you demonstrate strong backend and system-level thinking—exactly what interviewers want.