Javarevisited

A humble place to learn Java and Programming better.

Member-only story

Java Interview Question: Remove Inactive Users Efficiently

Efficient User Cleanup in Large Datasets

Suraj Mishra
Javarevisited
Published in
4 min readJan 27, 2025

--

Problem Description

Imagine you’re working on a user access control system for an application, and you need to clean up a list of users who have been marked as inactive. Your goal is to remove all inactive users (status = INACTIVE) from the list while keeping the operation efficient and minimizing memory usage.

The current solution creates a new list to store active users, which is memory inefficient for large lists.

  • How would you modify the solution to improve memory usage by operating ?
  • What is the time complexity of your proposed solution, and how does it compare to the existing approach?

https://javabulletin.substack.com/subscribe

  • The existing approach Iterates over each customer filters only the active ones and then maps it to a new array list.
    public static void main(String[] args) {
List<Customer> customers = new ArrayList<>();
Random random = new Random();
IntStream.rangeClosed(1, 100_000_000).forEach(i -> {…

--

--

Javarevisited
Javarevisited

Published in Javarevisited

A humble place to learn Java and Programming better.

Suraj Mishra
Suraj Mishra

Written by Suraj Mishra

Staff Software Engineer @PayPal ( All opinions are my own and not of my employer )

Responses (2)