Siemens Coding Question – Solved

3 Live
How to Attempt? Chocolate Arrangement Alex loves chocolate a lot. His brother Sam gifts him 2^N boxes of chocolate. These boxes are arranged in 2 rows denoted by 2 arrays A and B both of size N. Each box of chocolate contains some number of chocolates which is represented by A[i] and B[i] (for 1 <= i <= N). Alex wants the boxes of chocolate in those 2 rows to be arranged in such a way that the boxes containing an equal number of chocolates are placed at the same index i.e. if A[x] and B[y] are equal, then x should be equal to y. You have to help Alex arrange the rows of boxes such that the maximum number of pairs of equal boxes can be placed at the same index, in the manner that Alex wants. Return the maximum number of pairs of boxes that can be successfully arranged in the manner specified above. Note: You can rearrange the row only by cyclically shifting the row to the left or to the right. A single cyclic shift to the left is an operation that sets A[0] = A[1], A[1] = A[2], ..., A[N-1] = A[0] simultaneously, and a single

Asked in: Siemens

Image of the Question

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