Symmetric Mountains
InterviewTime limit1sMemory limit1024 MB
For each crop length, finds the minimum sum of height differences between mirrored mountain pairs over all consecutive crops of that length.
- Level
Medium4 of 10
- Topics
- Brute force, Array
- Solved
- No attempts yet
Problem
Rebecca is a tour guide and is trying to market the Rocky Mountains for her magazine. She recently took a picture of mountains, where the -th mountain from the left has height . She will crop this picture for her magazine by possibly removing some mountains from the left side and possibly removing some mountains from the right side. A crop consists of consecutive mountains from the -th to the -th mountain, where . Rebecca wants the most symmetric crop.
The asymmetric value of a crop is the sum of for all . In other words, pair the mountains from the outside in toward the center, compute the absolute height difference of each pair, and add them up.
Rebecca does not know how wide the picture needs to be. For every possible crop length, find the asymmetric value of the most symmetric crop, which is the crop with the minimum asymmetric value.
Input
The first line contains an integer , the number of mountains. The second line contains space-separated integers, where the -th integer is .
Output
Print on one line space-separated integers. The -th integer is the asymmetric value of the most symmetric crop of length .
Constraints