Java Coding Interview(non-leetcode-style) - Top 10 Active Users by Login & Email Trust
Solving non-leetcode style Java coding problems
Problem
You’re building a user analytics system. Given a list of users, your task is to select the top 10 trusted active users based on certain rules.
User class:
Requirements:
Write a method:
public List<String> getTop10TrustedActiveEmails(List<User> users)that returns a list of up to 10 email addresses satisfying all of the following logic:
Filtering Rules: Only include users where:
isActive == trueemail != null,lastLoginDate != nulllastLoginDateis within the last 30 days from todayloginCountLast30Days >= 5
Deduplication Rules: Deduplicate by email.
If the same email appears more than once, keep the one with:
- The latestlastLoginDate- If tied, choose the one withemailVerified == true- If tied again, choose the one with the highestloginCountLast30Days- If still tied, choose the lexicographically smalleruserId
Final Ranking:
Sort the resulting users by:
loginCountLast30DaysdescendingThen by
lastLoginDatedescending
Return:
A list of email addresses (no duplicates)
Max size: 10
Solution
Filter Active Users



