June 03, 2024 |190 Views

    PROBLEM OF THE DAY : 02/06/2024 | Construct list using given q XOR queries

    Description
    Discussion

    Welcome to the daily solving of our PROBLEM OF THE DAY with Siddhartha Hazra. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Bit Manipulation but also build up problem-solving skills.

    Given a list s that initially contains only a single value 0. There will be q queries of the following types:

    • 0 x: Insert x in the list
    • 1 x: For every element a in s, replace it with a ^ x. ('^' denotes the bitwise XOR operator)

    Return the sorted list after performing the given q queries.

    Example 1:

    Input:
    q = 5
    queries[] = {{0, 6}, {0, 3}, {0, 2}, {1, 4}, {1, 5}}
    Output: 1
     2 3 7
    Explanation:
    [0] (initial value)
    [0 6] (add 6 to list) [0 6 3] (add 3 to list)
    [0 6 3 2] (add 2 to list)
    [4 2 7 6] (XOR each element by 4)
    [1 7 2 3] (XOR each element by 5) The sorted list after performing all the queries is [1 2 3 7]. 

    Give the problem a try before going through the video. All the best!!!
    Problem Link: https://practice.geeksforgeeks.org/problems-/construct-list-using-given-q-xor-queries/1