GOOGLE Coding Question – Solved

11 Live
Remaining elements You are given two arrays A and B of size N. Your task is to remove some numbers from array A such that the following conditions are met: 1. The remaining elements of array A are strictly increasing from left to right. 2. The corresponding elements from B must also be extracted. For example, if you have removed the ith element of array A, then the ith element of array B must also be pulled out. Consider 1-based indexing. Find the maximum strength of the remaining elements of array B. Suppose the remaining elements of array B are Bn, Br2, ..., Bir, 1 ≀ I1, I2, ..., Ir < N, then the strength of array B is calculated as B1 - Bm + Bg - .... (-1)^r-1 * B. Note: 1-based indexing is followed. Input format: - The first line contains an integer T denoting the number of test cases. - The next line contains an integer N denoting the size. - The next two lines contain N space-separated integers denoting the elements of arrays A and B respectively. Output format: - Print the maximum strength of the remaining elements of array B in a new line. Constraints: - 1 ≀ T ≀ 10 - 1 ≀ N ≀ 2 Γ— 10^3 - 1 ≀ Ai, Bi ≀ 10^6 Sample input: 7 3 1 4 5 6 20 30 40 10 20 Sample output: 50 85

Asked in: GOOGLE

Image of the Question

Question Image Question Image Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |