Problem · Hash Table

Goto Largest Bucket

Learn this problem
EasyDatabricksINTERNOA

Problem statement

Process commands in a virtual environment:

  • goto <bucket_name> changes the current bucket. The bucket is guaranteed to exist.
  • create <filename> creates that file in the current bucket. If the same filename already exists in that bucket, nothing happens.

Return the bucket containing the largest number of distinct files after all commands. The first command is a goto, at least one command is a create, and the largest bucket is unique.

Function

databricksGotoLargestBucket(commands: String[]) → String

Examples

Example 1

commands = ["goto bucketA", "create fileA", "create fileB", "create fileA", "goto bucketB", "goto bucketC", "create fileA", "create fileB", "create fileC"]return = "bucketC"

bucketA contains two distinct files, bucketB contains none, and bucketC contains three.

Constraints

🦅🙉

More Databricks problems

drafts saved locally
public String databricksGotoLargestBucket(String[] commands) {
  // write your code here
}
commands["goto bucketA", "create fileA", "create fileB", "create fileA", "goto bucketB", "goto bucketC", "create fileA", "create fileB", "create fileC"]
expected"bucketC"
checking account