Given N points, count the number of squares, including rotated squares.
Unlock detailed company stats for this questionUpgrade
Approaches: O(N^4) brute force; O(N^2) time/O(N^2) space using midpoints of pairs as potential diagonals; O(N^2) using a helper that returns the other two diagonal points plus a set of input points, handling double-counting.
Expect follow-ups like
- Would the given function handle duplicate points?
- Now count rhombi instead.
Format · Phone screen coding.
Community answers
No answers contributed by the community yet.


