Engineering With Java

Engineering With Java

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

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

This post is for paid subscribers

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