Branch with the Most Files
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.