Company: Morgan stanley_12may
Difficulty: medium
Security Key for Data Packets Problem Description While transmitting data, N packets are given a unique ID from 0 to N-1 . Packet i carries a payload of size dataSize[i] . A security key is derived from the packet sizes by repeating the following protocol step until no packet is left: Choose a group of one or more consecutive packets in the current sequence that all carry the same data size. Remove that group. If the group contained K packets, this step contributes K^2 to the key. The packets that remain close up, keeping their relative order, and form the new current sequence. Different choices produce different totals. The security key is the largest total that any sequence of steps can achieve. Write an algorithm to compute the security key for the given N data packets. Input The first line contains an integer num , representing the number of data packets ( N ). The second line contains N space-separated integers dataSize[0], dataSize[1], ..., dataSize[N-1] , representing the size o