Skip to main content

Command Palette

Search for a command to run...

Finding the Users Active Minutes

Published
2 min read
Finding the Users Active Minutes
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

You are given the logs for users' actions on LeetCode, and an integer k. The logs are represented by a 2D integer array logs where each logs[i] = [ID<sub>i</sub>, time<sub>i</sub>] indicates that the user with ID<sub>i</sub> performed an action at the minute time<sub>i</sub>.

Multiple users can perform actions simultaneously, and a single user can perform multiple actions in the same minute.

The user active minutes (UAM) for a given user is defined as the number of unique minutes in which the user performed an action on LeetCode. A minute can only be counted once, even if multiple actions occur during it.

You are to calculate a 1-indexed array answer of size k such that, for each j (1 <= j <= k), answer[j] is the number of users whose UAM equals j.

Return the array answer as described above.

LeetCode Problem - 1817

class Solution {
    public int[] findingUsersActiveMinutes(int[][] logs, int k) {

        int[] result = new int[k]; // Initialize the result array to store counts of users' active minutes
        Map<Integer, Set<Integer>> map = new HashMap<>(); // Initialize a map to track users' active minutes

        // Iterate through the logs
        for (int[] keyValue : logs) {
            // For each log entry, add the minute to the corresponding user's set of active minutes
            map.computeIfAbsent(keyValue[0], key -> new HashSet<>()).add(keyValue[1]);
        }

        // Iterate through the map entries
        for (Map.Entry<Integer, Set<Integer>> entry : map.entrySet()) {
            // Increment the count for the number of users with the specific number of active minutes
            result[entry.getValue().size() - 1]++;
        }

        return result; // Return the result array
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.