Azber's Tooth Marks
InterviewTime limit3sMemory limit1024 MB
Given sorted tooth mark positions, find every gap k where each mark has another mark exactly k away from it.
- Level
Medium5 of 10
- Topics
- Array, Hash map, Brute force
- Solved
- No attempts yet
Problem
Food at home keeps disappearing, and you suspect your neighbor, the bear Azber. Today you finally found decisive evidence: tooth marks on a chocolate bar.
You think Azber bit the chocolate bar with two large canines and left several marks.
Treat the chocolate bar as a number line. Azber can leave tooth marks on the bar by following these rules.
- At first, the bar has no marks.
- When the gap between Azber's canines is (), Azber can choose a number and leave marks at positions and on the bar. Azber can repeat this action or more times.
- If marks are left on the same position several times, only the last mark is visible.
You write down every possible canine gap based on the tooth marks on the bar, so you can check them when you meet Azber later.
Given the positions of the tooth marks, find every number that can be Azber's canine gap.
Input
The first line contains the number of tooth marks on the chocolate bar. ()
The second line contains the positions of the tooth marks, separated by spaces, in ascending order. All are distinct. ()
Output
On the first line, print the number of possible canine gaps for Azber.
If is at least , print the possible gaps on the second line, separated by spaces, in ascending order.