Branch with the Most Files
Updated
Problem statement
Process the version-control log entries in logs in order. Initially no branch is selected.
switch branchselects the named branch, creating it with a count of zero if necessary.push filenameadds 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[]) → StringExamples
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 branchorpush filenamewith one separating space. - For this exercise, assume branch names and filenames have lengths from
1through100. - 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