← Morgan Stanley Interview Insights

Morgan Stanley·Software Engineer·Online Assessment (OA)·Intermediate

Intermediate
Jun 2026

Summary

Got a geometry/line-coverage problem from Morgan Stanley, the kind that looks deceptively clean on the surface but has some real edge cases hiding underneath. No frills, just code.

Questions Asked (1)

Q1

Given n points on a 2D coordinate plane, find the minimum number of straight lines needed so that every point lies on at least one line.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was greedy: find the line covering the most uncovered points, mark them, repeat.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the problem constraints and edge cases, then reduce it to a graph problem where points are vertices and lines are cliques. Discuss the general NP-hardness and present a practical approach for small n using backtracking with pruning, or a greedy heuristic for larger n.

Pro tip: Acknowledge the NP-hard nature of the general problem and propose a solution that balances optimality and efficiency, such as using bitmask DP for n ≤ 20 or a greedy set cover approximation for larger n, showing awareness of real-world constraints.

1. Clarify Requirements

Ask about constraints: n's maximum value, whether points are distinct, and if lines must be unique. This determines the appropriate algorithmic approach.

2. Model as Graph Problem

Represent each point as a vertex and each possible line as a clique (set of collinear points). The goal is to cover all vertices with minimum cliques, which is equivalent to minimum clique cover.

3. Analyze Complexity

Explain that minimum clique cover is NP-hard in general, so exact solutions are feasible only for small n. For larger n, approximation or heuristics are needed.

4. Propose Algorithm

For small n (≤20), use bitmask DP or backtracking to find the exact minimum. For larger n, use a greedy set cover approach: repeatedly choose the line covering the most uncovered points.

5. Discuss Trade-offs

Compare exact vs. approximate methods, highlighting time complexity, optimality, and practical applicability. Mention that the greedy algorithm gives an O(log n) approximation.

Key Points to Mention

  • Minimum clique cover equivalence
  • NP-hardness of the general problem
  • Bitmask DP for small n (n ≤ 20)
  • Greedy set cover approximation for large n
  • Time and space complexity analysis
  • Edge cases: all points collinear, duplicate points, n=1

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.