Company: Autodesk Sde intern_1may
Difficulty: medium
You are monitoring the building density in a district of houses. The district is represented as a number line, where a house can be built at each numbered point on the line if at least one of the neighboring points is not occupied. Initially, there are no houses in the district. You are given queries , an array of integers representing the locations of new houses in the order in which they will be built. After each house is built, your task is to find the longest segment of contiguous houses in the district. Return an array of integers representing the longest segment of contiguous houses after each respective house from queries is built. NOTE: It's guaranteed that all of the house locations in queries are unique and no house was built at a point with existing houses on both left and right adjacent points. Assume that array indices are 0-based. Example For queries = [2, 1, 3] , the output should be solution(queries) = [1, 2, 3] . Let's look at what happens at each step: After queries[0