Dynamic Arrays / Lists

Data Structures & Libraries DSA practice problem on Onlearn.

Difficulty: easy.

Topics: Binary Search Algorithm, Data Structures, Time Complexity, Space Complexity, Big O Notation, Loops, Conditional Statements, complexity analysis, array, divide and conquer, search space optimization, iterative vs recursive, binary search, Sorted & Rotated Arrays, Search Space.

Dynamic Array Operations You are given an initial list of integers and a series of operations to perform on this list. Each operation can be one of three types: 1. ADD x: Add integer x to the end of the list. 2. REMOVE x: Remove the first occurrence of integer x from the list. If x is not found, do nothing. 3. CHECK x: Check if integer x exists in the list. If it exists, output "YES"; otherwise, output "NO". After all operations are performed, output the final state of the list. Input Specification The first line contains an integer N (1 <= N <= 10^5), representing the number of initial elements in the list. The second line contains N space separated integers, representing the initial elements of the list. The third line contains an integer Q (1 <= Q <= 10^5), representing the number of operations. The next Q lines each contain an operation in the format specified above (ADD x, REMOVE x, or CHECK x). Output Specification For each CHECK operation, print "YES" or "NO" on a new line. After all operations, print the final elements of the list, space separated, on a new line. If the list is empty, print nothing. Constraints 1 <= N <= 10^5 1 <= Q <= 10^5 10^9 <= x <= 10^9 for all integers and operations. Sample Test Cases Sample Input 1 Sample Output 1