Draw a Vertical Cut Through the Fewest Feed Card Rows

Last updated: November 29, 2026

Quick Overview

A feed layout has rows of cards with integer widths, every row having the same total width. Draw one vertical line from top to bottom (not on the outer edges) that crosses the fewest cards, where passing along a card boundary does not count as crossing, and return that number.

Meta
Coding & Algorithms
Frontend Engineer
Meta
November 29, 2026
Frontend Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


A feed layout has rows of cards with integer widths, every row having the same total width. Draw one vertical line from top to bottom (not on the outer edges) that crosses the fewest cards, where passing along a card boundary does not count as crossing, and return that number.

A hashing problem about counting shared positions, framed around a card grid layout like those on Facebook or Instagram web. The interviewer wants you to flip the question from minimizing crossings to maximizing aligned edges.

What the Interviewer Expects
  • Reframes the goal as finding the x position where the most rows have an edge
  • Builds prefix widths per row, excluding the final edge
  • Counts edge positions in a hash map
  • Returns rows minus the best edge count
  • Gives O(total cards) time
Key Topics to Cover
hash map
prefix sum
counting
reframing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Allow k vertical cuts; how does the problem change?
  • Rows can have different total widths. What is a sensible definition?
  • How would you precompute this for many layout variants in a design tool?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: rows, a list of lists of positive integers, each list summing to the same width W. Output: the minimum number of cards crossed by a vertical line at some integer x with 0 < x < W. If W is 1 (...

High-Level Design

A line at position x avoids crossing a card in a row exactly when that row has an edge at x. So the best line is at the x where the most rows have an internal edge. For each row, walk its prefix sums ...


Submit Your Answer
Markdown supported