Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Priority Queue Data Structure Task

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Priority Queue Data Structure Task. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Solve a file/folder data structure coding task using a Priority Queue.

Asked in the Virtual Onsite stage. Second coding problem in the onsite interview involving storage, subfolders, and files.

Implement largest_files(root, k). root is a nested dictionary: folders have name, type: "folder", and children; files have name, type: "file", and nonnegative size. Return up to k files as [full_path, size], ordered by decreasing size, breaking ties by lexicographically ascending full path. Paths use / between names and include the root folder. Return [] when k is zero or the tree contains no files.

Constraints

  • 1 <= number of nodes <= 1000
  • 0 <= k <= 1000
  • File sizes are nonnegative integers
  • Every node has a unique name among its siblings
  • The input is a valid acyclic folder tree

Function Signature

def largest_files(root, k):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output