Distinct Elements in a Stream
Submissions: 1191   Accuracy:

24.52%

  Difficulty: Basic   Marks: 1

Given an input stream of N integers (alongwith the operation on these integers), the task is to print the number of the distinct elements in the stream after each operation.
There can be two types of operations that can be performed:

Addition represented by A.
Deletion represented by R.

Input:
First line of the input contains an integer T denoting the number of test cases. Then T test case follows. First line of each test case contains an integer N denoting the number of operations to be performed on a stream. Next N lines two space separated elements, the operation to be performed and the key element.

Output:
For each operation output the number of the distinct characters in a stream on a new line.

Constraints:
1<=N<=106
1<=A[]<=106

Example:
Input:

1
8
A 5
A 5
A 7
R 5
R 7
A 1
A 2
R 2
Output:
1
1
2
2
1
2
3
2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: harshitsidhwa


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.