← Back to blog ByteDance OA CodeSignal Four-Question Debrief: Largest Square + Nearly Regular Crosses + String Reversal
ByteDance

ByteDance OA CodeSignal Four-Question Debrief: Largest Square + Nearly Regular Crosses + String Reversal

2026-06-09

I recently ran a student through a ByteDance Online Assessment on CodeSignal, very similar to the shared question bank you know from Uber / Roblox / HRT / TikTok, with the usual format of four questions in 70 minutes. If you've done OAs for these companies, the question types and patterns are basically the same. The difficulty isn't explosive, but to AC all of them in 70 minutes you still need to know CodeSignal's question types in advance—especially the boundaries and corner cases that are easy to fall into.

1. OA Structure Overview

Item Detail
Platform CodeSignal (shared bank, like Uber/Roblox/HRT/TikTok)
Format 4 questions in 70 minutes
Difficulty Medium; the point is accuracy + time management
Easy losses Boundary / corner cases

2. Problem 1: Largest Square in the City Skyline

Problem

Each element of cityline is a skyscraper's height, each of width 1, placed directly adjacent with no gaps. Find the largest square area that fits within this row.

Example: cityline = [1, 2, 3, 2, 1] → output 4 (multiple 2x2 fit; nothing larger).

Approach

A square of side k fits iff there exist k consecutive buildings all of height >= k. Larger sides are harder to satisfy—monotone—so binary search the side length with an O(n) check each time:

def solution(cityline: list[int]) -> int:
    n = len(cityline)

    def can_fit(k: int) -> bool:
        run = 0                       # run of buildings with height >= k
        for h in cityline:
            run = run + 1 if h >= k else 0
            if run >= k:
                return True
        return False

    lo, hi, best = 1, min(n, max(cityline)), 0
    while lo <= hi:
        mid = (lo + hi) // 2
        if can_fit(mid):
            best = mid
            lo = mid + 1
        else:
            hi = mid - 1
    return best * best                # area = side^2

Complexity O(n log n). Trap: the side upper bound is min(building count, tallest building)—don't use only n or only the max height.

3. Problem 2: Count Nearly Regular Crosses

Problem

In a matrix, a cross is formed by the intersection of one row and one column. If all elements on the cross are equal, it's a regular cross; if all are equal except possibly the element at the row-column intersection, it's a nearly regular cross (regular crosses count as nearly regular too). Return the number of nearly regular crosses.

Required complexity no worse than O(R*C*(R+C)). The sample matrix outputs 10.

Approach

For each intersection (r, c), the cross = row r + column c (minus the duplicated intersection). "All equal except the intersection" means: the row, excluding column c, is all equal, the column, excluding row r, is all equal, and those two common values are equal. Preprocess each row/column for "is it single-valued after dropping at most one element, and what is that value":

def solution(matrix: list[list[int]]) -> int:
    R, C = len(matrix), len(matrix[0])

    def line_profile(values):
        # returns (common value, set of allowed exception indices that can be the intersection)
        from collections import Counter
        cnt = Counter(values)
        if len(cnt) == 1:
            return values[0], set(range(len(values)))    # all equal; any position can be the intersection
        if len(cnt) == 2:
            (v1, c1), (v2, c2) = cnt.most_common()
            if c2 == 1:                                   # one outlier; it must be the intersection
                idx = values.index(v2)
                return v1, {idx}
        return None, set()

    row_prof = [line_profile(matrix[r]) for r in range(R)]
    col_prof = [line_profile([matrix[r][c] for r in range(R)]) for c in range(C)]

    total = 0
    for r in range(R):
        rv, r_ok = row_prof[r]
        if rv is None and not r_ok:
            continue
        for c in range(C):
            cv, c_ok = col_prof[c]
            # row can take c as intersection, column can take r as intersection, common values match
            if c in r_ok and r in c_ok and rv == cv:
                total += 1
    return total

Complexity O(RC) (preprocessing O(RC)), better than required. Trap: the intersection element itself is free; only the non-intersection elements must equal the common value.

4. Problem 3: Optimal String Reversal

Problem

Given a string word, you can form new strings by reversing the first or last k characters. Reversing the first k: |w0...wk-1|wk...|wk-1...w0|wk...; reversing the last k applies similarly to the tail. The goal is to obtain the lexicographically smallest string.

Approach

Prefix/suffix reversal is a local reverse; the key is greedily choosing operations that lower the lexicographic order. In practice, first implement the baseline "enumerate all prefix/suffix reversals, take the smallest," then discuss the reachable set under multiple operations:

def best_reversal(word: str) -> str:
    best = word
    n = len(word)
    for k in range(1, n + 1):
        prefix_rev = word[:k][::-1] + word[k:]            # reverse first k
        suffix_rev = word[:n - k] + word[n - k:][::-1]    # reverse last k
        best = min(best, prefix_rev, suffix_rev)
    return best

Trap: watch the range of k (1..n) and the slice boundary for "last k"—CodeSignal hidden tests love this kind of off-by-one.

5. Summary

The ByteDance CodeSignal OA is four questions in 70 minutes, with types heavily overlapping the Uber/Roblox/HRT/TikTok shared bank: skyline binary search, matrix cross preprocessing, and string reversal are all not obscure—but AC-ing all of them comes down to accuracy + time management, especially boundary handling. Building muscle memory on CodeSignal beforehand beats improvising on the spot.


FAQ

Q1: What platform is the ByteDance OA, and how many questions?

CodeSignal, four questions in 70 minutes, with a bank closely matching the Uber/Roblox/HRT/TikTok shared questions. Difficulty is medium; the core is accuracy and time management.

Q2: How do I think about the largest-square skyline question?

Binary search the side length k, checking "do k consecutive buildings all have height >= k," which is O(n) per check, O(n log n) total. Note the side upper bound is min(building count, tallest building).

Q3: What is the key to nearly regular crosses?

Preprocess each row/column for "single-valued after dropping at most one element, and the common value." The intersection element is free; you count when both the row and column's non-intersection elements equal the same common value. Complexity O(R*C).

Q4: How should I prepare for the ByteDance OA?

Build muscle memory on CodeSignal with the shared bank (binary search, matrix preprocessing, string simulation), focusing on edges and time allocation. For timed mock practice on the four questions, or real-time OA proxy / OA assist support, send the job JD so we can predict the question types and build a plan.


Preparing for the ByteDance OA?

The ByteDance CodeSignal OA tests the shared bank + accuracy + time management. oavoservice offers full ByteDance mock support: timed simulations of skyline / matrix / string problems, edge-case trap walkthroughs, and 70-minute pacing practice, plus real-time OA proxy / OA assist support. Coaches know the CodeSignal shared bank and scoring logic.

Add WeChat Coding0201 now to get ByteDance questions and mock practice.

Contact