FastPrepBranch with the Most Files
Problems/Branch with the Most Files

Branch with the Most Files

Capital One logoCapital One● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report does not say how to handle ties and gives no number limits. Ties go to the branch that was pushed first. Our version is about 95% the same as the reported question.

Special thanks: 🌷 A special thank you to a lovely, amazing fren who shared that this question appeared again on November 20, 2026! (˶˃ ᵕ ˂˶) .ᐟ.ᐟ 💚

Process the version-control log entries in logs in order. Initially no branch is selected.

  • switch branch selects the named branch, creating it with a count of zero if necessary.
  • push filename adds one pushed-file event to the selected branch. Repeated filenames count as separate pushes.

Return the name of the branch with the greatest number of push events. If several branches tie, return the one that received its first push earliest. Return the empty string "" when no pushes occurred; this represents the absence of a branch.

For this exercise, assume every push follows a switch, each branch name and filename is a nonempty token without spaces, repeated filenames count separately, and ties use the earliest first push.

Function

branchWithMostFiles(logs: String[]) → String

Examples

Example 1

logs = ["switch main","push a.py","push b.py","switch dev","push c.py","switch main","push d.py"]return = "main"

The main branch receives three pushes and dev receives one, so the result is main.

Constraints

  • For this exercise, assume 0 <= logs.length <= 10^5.
  • Every entry is exactly switch branch or push filename with one separating space.
  • For this exercise, assume branch names and filenames have lengths from 1 through 100.
  • Every push occurs after at least one switch.

More Capital One Online Assessment questions

  • Count Pairs of Overlapping SquaresOA · Seen Nov 2026
  • Distinct Values on Maximum-Sum FramesOA · Seen Nov 2026
  • Simulate Orchard Rot SpreadOA · Seen Nov 2026
  • Lowest Number in an Open RangeOA · Seen Nov 2026
  • Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
  • Earn the Most 🐝OA · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
  • Arithmetic Triplets After QueriesOA · Seen Oct 2026
  • Count One-Swap Number PairsOA · Seen Oct 2026

Similar questions at other companies

  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Filter Transaction Logs and Calculate Reliability MetricsStripe · OAStripe interview questions
  • Return RecordsAmazon · OA
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Versioned Recipe SystemThe Trade Desk · OA
  • Cheating CodemakerJane Street · OAJane Street interview questions
  • Aggregate Paginated Project Run RecordsReplit · OA
  • Numbers Station Message DecoderOptiver · OAOptiver interview questions
  • Hidden ArtifactsIMC Trading · OAIMC Trading interview questions
  • Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions

Interview reports that mention this question

  • Capital One Experienced Engineer Power Day and OA: 6 Experiences

Capital One interview experiences

  • Capital One Coding OA Questions: 3 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 branchWithMostFiles(String[] logs) {
        // Write your code here.
    }

}
Checking account…