![]() |
VOOZH | about |
Given Q queries of three types where every query consists of a number.
The task is to write a program that performs the above queries.
Note: Elements in queries 1 and 2 are distinct and 0 <= num <= 105.
Examples:
Input:
Q = 5
Query of type 1: num = 3
Query of type 2: num = 5
Query of type 1: num = 2
Query of type 1: num = 4
Query of type 3: num = 3
Output: element on the right: 1 element on the left: 2
After query 1, the element positioning is 3
After query 2, the element positioning is 35
After query 3, the element positioning is 235
After query 4, the element positioning is 4235
So there is 1 element to the right and 2 elements on the left of 3 when
query 3 is called.
The following steps can be followed to solve the above problem.
Below is the implementation of the above approach:
The number of elements to right of 3: 1 The number of elements to left of 3: 2
Time Complexity: O(1) for every query.
Auxiliary Space: O(MAXN), where MAXN is 105.