Given an arraylist of integers. The task is to perform operations on ArrayList according to the queries and print output for the required queries.
Note: use Collections.sort() to sort the list in natural order, Collections.reverseOrder() to arrange the elements in reverse, get() to return the element at index of the list, binarySearch() to find the index of the specified element in the list.
Input Format:
First line of input contains number of testcase T. For each testcase, first line of input contains Q, number of queries. Next line contains Q queries as:
a x : inserts the element x at the end of the list.
i : arrange the list in increasing order.
d : arrange the list in decreasing order.
s y : search for the element y in the list and prints the first-index(for duplicate) (0-based indexing) of that in the list. -1 if not found.
Output Format:
For each testcase, print the output according to the queries.
Your Task:
Your task is to complete the functions insert(), IncOrder(), Search() and DecOrder() such that driver code will be able to perform required queries.
Constraints:
1 <= T <= 100
1 <= A[i] <= 10^{6}
1 <= Q <= 10^{3}
Example:
Input:
2
6
a 2 a 3 a 4 a 2 i s 2
5
a 2 a 3 a 3 d s 5
Output:
0
-1
Explanation:
Testcase 1: After inserting elements, list is (2, 3, 4, 2) and arranging them in ascending order, we have list as (2, 2, 3, 4). Now, serching for 2, first occurence is at 0^{th} index.
Testcase 2: After inserting elements, list is (2, 3, 3) and arranging them in descending order, we have list as (3, 3, 2). Finding 5 gives -1, as 5 is not present.
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.
akhyasharma01 | 467 |
ASWATHAMA | 399 |
john_wick | 360 |
mmzeineddine | 295 |
PiyushPandey4 | 271 |
PiyushPandey4 | 614 |
ASWATHAMA | 561 |
akhyasharma01 | 547 |
john_wick | 521 |
rahulnishad96 | 442 |
blackshadows | 5362 |
Ibrahim Nash | 5242 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4598 |