FastPrepStable Sort of Logs With Three Types
Problems/Stable Sort of Logs With Three Types

Stable Sort of Logs With Three Types

Capital One logoCapital One● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A September 2016 Capital One software engineer report, listing questions from a final on-campus interview round, asks for a stable sort of a collection of logs that come in three types, A, B and C.

The report does not say how a log is written. Here each log is the text type, a colon and the log text, the answer lists all type A logs, then B, then C, and logs of the same type keep the order they had in the input. There are up to 800 logs. These are our choices.

Our version is about 75% the same as the reported question.

Every entry of logs is written as "T:payload", where the type T is one of A, B and C. Rearrange the entries so that all A logs come first, then all B logs, then all C logs.

The sort must be stable: two logs of the same type stay in the same relative order as in logs. Only the type decides the order; the payload never does.

Function

sortLogs(logs: String[]) → String[]

Examples

Example 1

logs = ["C:disk","A:login","B:cache","A:logout","C:net","B:db"]return = ["A:login","A:logout","B:cache","B:db","C:disk","C:net"]

The A logs come first in the order they appeared (login, logout), then the B logs (cache, db), then the C logs (disk, net).

Example 2

logs = ["B:x","B:a"]return = ["B:x","B:a"]

Both logs have the same type, so neither moves: B:x stays before B:a. The text after the colon plays no part in the order.

Example 3

logs = ["C:z","A:y"]return = ["A:y","C:z"]

The A log moves in front of the C log; each of the two types present has just one log.

Constraints

  • 1 <= logs.length <= 800
  • Each log is a type letter A, B or C, a colon, and 1 to 10 lowercase letters or digits.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Group Transactions by HourAffirm · ONSITE INTERVIEWAffirm interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Meeting RoomsGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Sort Products by Aisle With Frozen Items LastInstacart · ONSITE INTERVIEWInstacart interview questions
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Sort Documents Left to RightFigma · ONSITE INTERVIEWFigma interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public String[] sortLogs(String[] logs) {
        // Write your code here.
    }
}
Checking account…