Department Seating Metrics
Updated
Problem statement
Each cell in a rectangular seating grid contains the department ID of its employee. Compare the layouts before and after a move by returning four values:
- The number of departments whose entire membership forms one four-neighbor connected group in before.
- The sum of Manhattan distances over all unordered pairs of employees in the same department in before.
- The connected-department count in after.
- The same-department pair-distance sum in after.
A singleton department is connected. Diagonals do not connect cells. Manhattan distance between (r1,c1) and (r2,c2) is |r1-r2|+|c1-c2|. Count each unordered pair once.
More fully connected departments is better on the first metric; a smaller distance sum is better on the second. Return both metrics without combining them into a final score. Both layouts have the same department membership counts.
Function
seatingMetrics(before: int[][], after: int[][]) → long[]Examples
Example 1
before = [[1,2],[2,1]]after = [[1,1],[2,2]]return = [0,4,2,2]Before the move, neither department is connected and each contributes distance 2. After the move, both departments are connected and each pair has distance 1.
Example 2
before = [[7,7,7]]after = [[7,7,7]]return = [1,4,1,4]The one department is connected in both layouts. Its three unordered pair distances are 1, 2, and 1, summing to 4.
Constraints
- 1 <= before.length, after.length <= 60
- 1 <= each row length <= 60
- Both grids are rectangular and have the same dimensions.
- 0 <= each department ID <= 1000000
- Both grids contain the same multiset of department IDs.
More Citadel Onsite Interview questions
- Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Removal PoolONSITE INTERVIEW · Seen Sep 2026
- Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
- Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
- Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
- Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
- 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026
- Cancellable Priority Task QueueONSITE INTERVIEW · Seen Jan 2026
- Dynamic Weighted SamplingONSITE INTERVIEW · Seen Jan 2026
Similar questions at other companies
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Explore an Unknown Grid and Find a PathLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Nearest Charging Station on a GridSpotify · ONSITE INTERVIEW
- Longest Matrix Walk with Two-Step ComparisonsGoogle · ONSITE INTERVIEWGoogle interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
- Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
- Mouse and Cheese ReachabilityMeta · ONSITE INTERVIEWMeta interview questions
- Number of IslandsTripjack · ONSITE INTERVIEWTripjack interview questions
- Number of IslandsTekion · ONSITE INTERVIEWTekion interview questions
- Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions