← Ge Interview Insights

Ge·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Two algorithmic questions for a GE software engineer role. Both were grid/string problems that look approachable but have a gap between the naive and optimal solutions that the interviewer clearly wanted you to bridge.

Questions Asked (2)

Q1

Given an M x N binary grid where 1s represent demand locations, find the single cell to place a store such that the total Manhattan distance to all demand cells is minimized. Return that minimum total distance.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I jumped straight into brute force, iterating every cell and summing distances to all 1s.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Recognize that Manhattan distance decomposes into independent row and column components, so the optimal row and column can be found separately by minimizing the sum of absolute differences. Use the median of the demand cells' row and column coordinates as the optimal location, then compute the total distance. This yields an O(K log K) solution where K is the number of demand cells, which is efficient for large grids.

Pro tip: Mention that the median minimizes the sum of absolute deviations, and if there are multiple medians (even number of points), any point between the two middle values works. Also note that the store must be placed on a grid cell, but the median will always be an integer coordinate if demand cells have integer coordinates.

1. Understand the problem and decompose distance

Explain that Manhattan distance between two points (r1,c1) and (r2,c2) is |r1-r2| + |c1-c2|, so the total distance to all demand cells is the sum of row distances plus the sum of column distances. These can be minimized independently.

2. Find optimal row and column using median

Collect all row coordinates of demand cells, sort them, and pick the median as the optimal row. Similarly, collect all column coordinates, sort them, and pick the median as the optimal column. The optimal store location is (median_row, median_column).

3. Compute the minimum total distance

Iterate through all demand cells and sum the Manhattan distances from the chosen store location. Return this sum as the minimum total distance.

4. Analyze time and space complexity

Sorting the row and column arrays takes O(K log K) time, where K is the number of demand cells. Computing the total distance takes O(K) time. Space complexity is O(K) for storing the coordinates.

5. Discuss edge cases and trade-offs

Consider cases with no demand cells (return 0 or handle appropriately), a single demand cell (distance 0), and multiple medians. Also mention that a brute-force approach checking all M x N cells would be O(M*N*K), which is inefficient for large grids.

Key Points to Mention

  • Manhattan distance decomposes into independent row and column components.
  • The median minimizes the sum of absolute deviations.
  • Optimal location is at the median of row coordinates and median of column coordinates.
  • Time complexity: O(K log K) due to sorting, where K is number of demand cells.
  • Space complexity: O(K) for storing coordinates.
  • Brute-force approach is O(M*N*K) and is inefficient for large grids.

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

Q2

Given a string of Y and N characters representing customer arrivals by hour, find the earliest closing time t in [0, n] that minimizes the penalty, where staying open during an N hour or closing during a Y hour each cost 1.

Algorithms & Data Structures
Author's notes

This one clicked faster.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, restate the problem to ensure you understand the penalty definition: each mismatch between the chosen closing time and the actual arrival pattern costs 1. Then, propose an efficient algorithm, such as computing prefix sums of Y's and N's to evaluate all possible closing times in O(n) time, and finally discuss edge cases and potential optimizations.

Pro tip: Mention that the penalty function is convex or can be minimized by scanning once, showing you recognize the monotonicity and can avoid brute force. Also, clarify that closing at time t means you are open for hours 0 to t-1, so the penalty is the number of Y's in [t, n) plus the number of N's in [0, t).

1. Clarify the problem and penalty definition

Restate the problem in your own words: given a string of Y/N, choose t in [0,n] to minimize mismatches. Confirm that penalty = (number of N in first t hours) + (number of Y in remaining n-t hours).

2. Derive a formula for penalty at any t

Let totalY be the total number of Y's. Then penalty(t) = (t - prefixY[t]) + (totalY - prefixY[t]) = t + totalY - 2*prefixY[t], where prefixY[t] is the number of Y's in the first t hours. This simplifies the computation.

3. Compute prefix sums and find minimum

Precompute prefixY for all t from 0 to n. Then iterate t from 0 to n, compute penalty(t) using the formula, and track the minimum. This takes O(n) time and O(n) space (or O(1) extra space if you compute on the fly).

4. Handle edge cases and return earliest t

Consider t=0 (closed all day) and t=n (open all day). If multiple t give the same minimum penalty, return the smallest t. Also, discuss if the input can be empty or contain other characters.

5. Analyze complexity and potential optimizations

State that the solution is O(n) time and O(1) extra space if you compute prefixY on the fly. Mention that you could also use a single pass to compute the minimum without storing all prefix sums.

Key Points to Mention

  • Penalty definition: cost of staying open during N hours plus cost of closing during Y hours.
  • Prefix sum technique to efficiently count Y's in any prefix.
  • Formula: penalty(t) = t + totalY - 2*prefixY[t].
  • Linear scan to find minimum penalty and earliest t.
  • Time complexity O(n) and space complexity O(1) if optimized.
  • Edge cases: t=0, t=n, empty string, all Y's or all N's.

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