Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

LeetCode-Style Coding Task

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

Your question is LeetCode-Style Coding 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

An AMD ROCm runtime must schedule kernel launches on a command stream. Kernels with the same name require at least n other time slots between launches of that kernel. Each slot can run one kernel, or remain idle. Return the minimum number of slots needed to execute all launches.

Formal Specification

Implement least_interval(tasks, n), where tasks is a list of strings representing kernel names and n is a nonnegative integer cooldown. Return an integer representing the shortest valid schedule length. You may reorder the launches, but every launch must execute exactly once.

Constraints

  • 1 <= len(tasks) <= 100000
  • 1 <= len(tasks[i]) <= 20
  • 0 <= n <= 1000000000
  • Kernel names are case-sensitive strings
  • Idle slots may be inserted between launches

Function Signature

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