#K32902. Nearest Occupied House
Nearest Occupied House
Nearest Occupied House
Given an array representing a row of houses, where each house is either vacant (denoted by 0) or occupied (denoted by 1), determine the distance from each house to the nearest occupied house.
For any two houses at positions \(i\) and \(j\), the distance between them is given by \(|i-j|\). The task is to compute an array where the \(i\)-th element is the minimum distance from the \(i\)-th house to any occupied house.
Example:
Input: 7 0 1 0 0 1 0 0 Output: 1 0 1 1 0 1 2
In this example, the distance from house 0 to the nearest occupied house (at index 1) is 1, house 1 is occupied so distance is 0, and so on.
inputFormat
The first line of input contains an integer \(n\) representing the number of houses.
The second line contains \(n\) space-separated integers. Each integer is either 0 or 1, representing whether a house is vacant or occupied, respectively.
outputFormat
Output a single line with \(n\) space-separated integers, where the \(i\)-th integer denotes the shortest distance from the \(i\)-th house to an occupied house.
## sample7
0 1 0 0 1 0 0
1 0 1 1 0 1 2