Java Newsletter

Java Newsletter

Share this post

Java Newsletter
Java Newsletter
Java Coding Interview(non-leetcode-style) - Top 10 Active Users by Login & Email Trust

Java Coding Interview(non-leetcode-style) - Top 10 Active Users by Login & Email Trust

Solving non-leetcode style Java coding problems

Suraj Mishra's avatar
Suraj Mishra
May 05, 2025
∙ Paid
5

Share this post

Java Newsletter
Java Newsletter
Java Coding Interview(non-leetcode-style) - Top 10 Active Users by Login & Email Trust
3
Share

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 == true

  • email != null, lastLoginDate != null

  • lastLoginDate is within the last 30 days from today

  • loginCountLast30Days >= 5

Deduplication Rules: Deduplicate by email.

  • If the same email appears more than once, keep the one with:
    -
    The latest lastLoginDate
    - If tied, choose the one with emailVerified == true
    - If tied again, choose the one with the highest loginCountLast30Days
    - If still tied, choose the lexicographically smaller userId

Final Ranking:

Sort the resulting users by:

  • loginCountLast30Days descending

  • Then by lastLoginDate descending

Return:

  • A list of email addresses (no duplicates)

  • Max size: 10

Solution

Filter Active Users

Keep reading with a 7-day free trial

Subscribe to Java Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Suraj Mishra
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share