MEDIUMasked at 1 company

Convert an Array Into a 2D Array With Conditions

A medium-tier problem at 86% community acceptance, tagged with Array, Hash Table. Reported in interviews at Gojek and 0 others.

Founder's read

You've got an array of integers and need to convert it into a 2D grid following strict rules about what can be placed in each row. This problem tests whether you understand when a greedy approach works and when you need hash table state to track what's already been used. Gojek has asked it. The acceptance rate is high, but that's because most people who see it have time to think it through. In a live OA with three other problems running, you might blank on the exact construction rule. If it hits your assessment and you're stuck on the mechanics, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
86%

Companies that ask "Convert an Array Into a 2D Array With Conditions"

If this hits your live OA

Convert an Array Into a 2D Array With Conditions is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The core trick is recognizing that you're building a 2D array where each row must be sorted, and each column (top to bottom) must also be sorted, with a constraint that no value can repeat within a row. The naive approach of just throwing elements into rows fails because you have to respect both the row-sort and column-sort invariants simultaneously. The right pattern: use a hash table to count frequencies, then greedily build each row by taking the next available element from your frequency map, ensuring it's both greater than the previous element in that row and valid for the column constraint. The pitfall is trying to sort the array first and then distribute it, which breaks the column-sort property. Most candidates overcomplicate the ordering logic. StealthCoder is the hedge if you can't reconstruct the greedy frequency-based construction under interview pressure.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Convert an Array Into a 2D Array With Conditions recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Convert an Array Into a 2D Array With Conditions interview FAQ

Why can't I just sort the array and split it into rows?+

Sorting then splitting violates the column-sort constraint. Each column must be sorted from top to bottom, but a simple linear split doesn't guarantee that. You need to build rows greedily while respecting both row and column ordering, which requires tracking frequencies with a hash table.

Is this problem actually asked at real companies?+

Yes, Gojek has reported it. The acceptance rate is 86%, which signals it's solvable but not trivial. High acceptance usually means the pattern is clear once you see it, but first-time solvers often overcomplicate the row-building logic.

What's the key insight I'm missing if I get stuck?+

The insight is that you must use a hash table to track element frequencies, then greedily build each row from left to right, only picking elements that maintain both row and column sort order. Skip elements in the frequency map if they violate the column constraint.

How does this relate to Array vs Hash Table topics?+

Array covers the 2D grid structure and iteration logic. Hash Table is the operational core: you count frequencies of input elements, then decrement them as you place elements into rows. Without the hash table, you can't efficiently check what's available and respect duplicate constraints.

What's the runtime and space complexity I should target?+

Most solutions aim for O(n log n) or O(n * m) time depending on how you organize the frequency building, and O(n) space for the hash table and output grid. The exact complexity depends on your construction strategy, but hash table lookups keep it linear in terms of the data structure operations.

Want the actual problem statement? View "Convert an Array Into a 2D Array With Conditions" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.