We are developing a graphics pack for a fantasy video game. The game contains mirrors that reflect images in a strange way. While normally a mirror laterally inverts (i.e., reverses) an entire image, these mirrors leave some parts of the image untouched, as if they are frozen, while reversing the remaining image around the frozen parts.
Consider a list of integer values representing an image (usually this would be a two-deimensional grid but for this problem we consider only one dimension). When the image is mirrored, all elements in the list are reversed in order except the elements at the positions corresponding to the frozen parts. The reversal of elements happens around the frozen indices.
An additional challenge is that to achieve this peculiar mirrored effect, you should reverse the contents of the list in-place, i.e., not using a second list in the process. The frozen indices are provided separately in the input.
Two example inputs and their corresponding outputs are shown below.
Input: image = [5, 3, 2, 6, 4, 0, 11, 9, -7, 13], frozen indices = [0, 2, 4, 6]
Output: [5, 13, 2, -7, 4, 9, 11, 0, 6, 3]
Explanation: All elements except the ones appearing on frozen indices (shown in red here) have been reversed in order.
Following is a visual representation of the example:
Here is a second example:
[6, 14, -4, 8, 9, 5, 0, 3, -1, 2, 12, 7]Input: image = [7, 14, 2, 8, -1, 5, 0, 3, 9, -4, 12, 6], frozen indices = [1, 3, 5, 7, 10]
Output: [6, 14, -4, 8, 9, 5, 0, 3, -1, 2, 12, 7]
Explanation: All elements except the ones appearing on frozen indices (shown in red here) have been reversed in order.
Implement the following function stub:
Use the following main to test your function: