Available question text
Given n houses in a line with one extra edge between x and y, count for each k the number of ordered house pairs whose shortest path length equals k. The challenge is to avoid O(n^2) all-pairs checks by using the fact that distances are min(|i-j|, |i-x|+1+|j-y|, |i-y|+1+|j-x|) and aggregating counts with arithmetic in O(n).
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 3015. Count the Number of Houses at a Certain Distance I
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source