ADOBE Coding Question – Solved

5 Live
School renovation Given N classrooms in a school and each classroom has a capacity of A[i] students. Bob is a builder and follows the instructions of Alice. Alice gives Q instructions of the following types: - 1 L 0: Move L classrooms to the left - 2 R 0: Move R classrooms to the right - 3 X Y: Remove the next classroom and add two new classrooms of capacity X and Y respectively to the right of the current classroom. (After performing this operation, classroom numbers change accordingly) Note: The queries are always valid. Initially, Bob is in the first classroom. After performing all instructions from Alice, print the capacity of all classrooms from 1 to the total number of classrooms. Function description Complete the solve function. This function takes the following 2 parameters and returns the required answer. Parameters: - A: Represents a linear array denoting the capacity of classrooms in the old school - queries: Represents a 2D array denoting instructions given by Alice of the given types Input format for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code. - The first line contains two space-separated integers N and Q denoting the initial number of classrooms and the number of instructions. - The second line contains N space-separated integers denoting initial classroom capacities. - Next Q lines contain queries of the form: - 1 L 0 - 2 R 0 - 3 X Y Output format After performing all instructions from Alice, return the capacity of all classrooms from 1 to K (K = total number of classrooms in the renovated school). Sample input 5 4 1 2 1 4 5 2 1 0 1 1 1 1 2 0 3 5 2 Sample output 1 2 5 7 4 1 1 Explanation Bob moves 1 classroom right, so he is in the 2nd classroom now. He moves 1 classroom left, so he is back to the 1st classroom. He moves 2 classrooms left (stays at index 0 since it's the start). Then, from current position (0), he removes the next classroom (2nd) with capacity 2 and adds classrooms with capacities 5 and 7. Final classroom capacities: [1, 2, 5, 7, 4, 1, 1]

Asked in: ADOBE

Image of the Question

Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| A company is organizing a batch process, where each batch consists of several t… |
| A digital art gallery has an art collection which is represented as a binary st… |
| Given a series of integer intervals, determine the size of the smallest set tha… |
| A forklift operator navigates products within an automotive parts warehouse. Th… |
| Number in a range You are given three integers L, R, and K. A number X repre… |
| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |