Multi-Field Sort for a Grid View With Empty Values Last

Last updated: November 29, 2026

Quick Overview

Given a list of records and an ordered list of sort rules (field plus ascending or descending), return the records sorted the way a grid view would show them. Empty cells must always sort to the bottom regardless of direction, and ties must keep the original order.

Airtable
Coding & Algorithms
Software Engineer
Airtable
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of records and an ordered list of sort rules (field plus ascending or descending), return the records sorted the way a grid view would show them. Empty cells must always sort to the bottom regardless of direction, and ties must keep the original order.

Every Airtable view carries a stack of sort rules, so this is a natural warm-up in a phone screen. The interviewer is checking that you handle mixed directions in one comparator, treat blanks the way users expect, and know what stability buys you.

What the Interviewer Expects
  • Clarify how empty values and case should sort
  • Write a single comparator that walks the sort rules in order
  • Keep blanks last in both ascending and descending order
  • Rely on or explain stable sorting for ties
  • State O(n log n * k) complexity for k rules
Key Topics to Cover
Custom comparators
Stable sorting
Null handling
Multi-key sort
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you sort a linked-record field or a multi-select field?
  • How would you sort 2 million records without blocking the event loop in a Node.js worker?
  • How do you keep the order stable when a cell is edited so rows do not jump under the user?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: records as {id, fields} and sorts as [(field, 'asc'|'desc'), ...]. Earlier rules take priority. Blank means None, empty string, or a missing key, and blanks go last no matter the directio...

High-Level Design

A naive approach reverses the list for descending fields, but that also moves blanks. Instead, write one comparator: for each rule, if both values are blank move to the next rule; if only one is blank...


Submit Your Answer
Markdown supported

Related Questions