这次跟大家分享一下我在 Capital One OA 里遇到的两道题,整体风格还是比较典型的北美银行类大厂笔试:既考算法思路的扎实度,又考对逻辑条件的精准把握。第一题是摩天大楼数组里的最大正方形面积,思路上很像“二分答案 + 区间验证”;第二题则是矩阵里统计“近规则十字”,重点在于对频次分布和中心元素特殊性的理解。两道题看似独立,其实都要求写出 clean code + 高效解法,否则很容易在时间里卡住。

Question 1: Largest Square Area
Problem:
You are given an array of integers representing the heights of skyscrapers in a row.
Find the maximum area of a square that can be placed among these buildings.
- A square of side length
mcan be placed if there exists a contiguous subarray of lengthmwhere every building’s height is at leastm. - The output should be the largest possible square area (
m²).
Example 1:
Input: heights = [3, 1, 3, 4, 3, 5]
Output: 9
Explanation:
The maximum square has side length 3 (for example, subarray [3,4,3] or [4,3,5]).
Area = 3 * 3 = 9.
Example 2:
Input: heights = [2, 2, 2]
Output: 4
Explanation:
The maximum square has side length 2 (subarray [2,2]).
Area = 2 * 2 = 4.
Question 2: Count of Nearly-Regular Crosses
Problem:
You are given a 2D integer matrix. A “nearly-regular cross” is defined as follows:
- A cross is formed by choosing a cell as the center, taking its row as the horizontal arm and its column as the vertical arm.
- Collect all numbers appearing in that row and column.
- If all numbers are identical, it is a regular cross (valid).
- If there are exactly two distinct numbers and one of them appears only once, and that unique element is the center cell, then it is a nearly-regular cross (also valid).
- Otherwise, it is not valid.
Return the total number of valid (regular + nearly-regular) crosses in the matrix.
Example 1:
Input:
matrix = [
[1, 1, 1],
[1, 2, 1],
[1, 1, 1]
]
Output: 1
Explanation:
Only the center cell (value 2 at position [1,1]) forms a nearly-regular cross.
All rows/columns contain only 1s except the center element = 2, so it is valid.
Example 2:
Input:
matrix = [
[5, 5, 5],
[5, 5, 5],
[5, 5, 5]
]
Output: 9
Explanation:
Every cell can be chosen as the center, and all of them form a regular cross.
Total = 9.
如果你也在准备 Capital One、Citadel、或者 Amazon 这一类 OA/VO,其实完全不用单打独斗。Programhelp 可以给你提供无痕远程联机助攻:比如实时语音提醒、debug 思路点拨、代码结构优化,让你在紧张的考试环境里少走弯路,把精力放在思考而不是卡壳上。很多同学反馈说,有了及时的提醒,就能稳定输出高质量答案,大大提升通过率。