AURIGO Coding Question – Solved

11 Live
You want to transmit N packets over a network where each packet needs to be encrypted before being sent. Each packet has some integer data represented by the array data[]. To encrypt the data, you need to perform operations on the N packets. You are given 3 more arrays of length Q: 1. typeOfOperation[]: each element denotes the type of operation to be performed on data[i] (1 or 2), 2. numberOfPackets[]: each element denotes the number of packets the operation applies to, 3. X[]: the value used in the operation. There are two types of operations: Type 1: Modify the first numberOfPackets[i] elements of data[] as (data[0] xor X[i], data[1] xor X[i], ..., data[a-1] xor X[i]). Type 2: Modify the last numberOfPackets[i] elements of data[] as (data[N-1] xor X[i], data[N-2] xor X[i], ..., data[N-a] xor X[i]). Your task is to return the encrypted data[] array after performing Q operations. Input: input1: Array of integers denoting data[] input2: Integer N, the length of data[] input3: Array of integers denoting typeOfOperation[] input4: Array of integers denoting numberOfPackets[] input5: Array of integers denoting X[] input6: Integer Q, the length of the above 3 arrays Output: Return an array of N integers denoting the encrypted data[]. Example 1: input1: [10, 9, 12, 3] input2: 4 input3: [1, 2] input4: [2, 1] input5: [5, 10] input6: 2 Output: [15, 12, 12, 9] Explanation: First operation is Type 1 on the first 2 packets: (10 xor 5) = 15, (9 xor 5) = 12 β†’ data = [15, 12, 12, 3] Second operation is Type 2 on the last 1 packet: (3 xor 10) = 9 β†’ data = [15, 12, 12, 9] Example 2: input1: [30, 10, 3] input2: 3 input3: [2, 1] input4: [1, 2] input5: [6, 18] input6: 2 Output: [12, 24, 5] Explanation: First operation is Type 2 on the last 1 packet: (3 xor 6) = 5 β†’ data = [30, 10, 5] Second operation is Type 1 on the first 2 packets: (30 xor 18) = 12, (10 xor 18) = 24 β†’ data = [12, 24, 5]

Asked in: AURIGO

Image of the Question

Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |