Question: In many real - world applications, such as network data monitoring or sales tracking, identifying unique events or items dynamically as data continuously arrives is

In many real-world applications, such as network data monitoring or sales
tracking, identifying unique events or items dynamically as data continuously
arrives is crucial. This assignment focuses on designing and implementing a
data structure that efficiently tracks the first unique number in a stream of
non-negative integers. Your task is to implement a system capable of adding
numbers to the stream and identifying the first unique number at any moment.
Problem Statement
Your implementation should support two primary operations:
- add(number): Adds a number to the data stream.
- showFirstUnique(): Returns the first number that appears only once in the
data stream. If there is no such number, return -1.
Key Requirements
Utilize a Hashmap to track the counts and positions of each number within a
linked list, efficiently managing duplicates and their occurrences.
Implement a Doubly Linked List to maintain numbers that currently have a
unique occurrence, preserving the order they were added.
Aim for O(1) average time complexity for both add and showFirstUnique
operations, ensuring optimal performance as the data stream grows.
Implement the add and showFirstUnique methods as specified.
Ensure your code is functional, as non-functional code will result in a zero
score.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!