Happy Neighborhood

Problem Overview

  • Determine the first day the neighborhood becomes happy: when at least one block of M consecutive houses is occupied.
  • Input: N houses, M target adjacency, and house[1..N] permutation giving the house occupied each day; Output: earliest day index.
  • Context: residents move into a linear street; happiness occurs with a contiguous occupied segment.
  • Source: Asked in Google interviews; a classic coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: