GOOGLE Coding Question – Solved

7 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

| 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… |