Find Minimum Load Index

Find Minimum Load Index

Given an array of integers and a maximum capacity, assign each number to the index with the minimum load among available indices.
Input:
An integer n (representing total available indices from 0 to n-1)
An array nums where each value nums[i] represents the maximum index that can be considered for assignment (exclusive)

For each number in nums, find the index to assign it based on these rules:
1, You can only consider indices from 0 to nums[i]-1
2, Among these indices, choose the one with the minimum current load
3, If multiple indices have the same minimum load, choose the smallest index
4, After assigning a number, increment the load at that index by 1

Return an array containing the chosen index for each number.

Example 1:
Input: n = 5, nums = [1, 2, 3]
Output: [0, 1, 2]
Explanation: Each number is assigned to the first available index with load 0

Example 2:
Input: n = 3, nums = [3, 0, 2, 1]
Output: [0, 0, 1, 1]
Explanation:
- For 3: consider indices [0,1,2], all have load 0, choose 0
- For 0: no indices to consider, default to 0
- For 2: consider indices [0,1], 0 has load 2, 1 has load 0, choose 1
- For 1: consider indices [0,1], 0 has load 2, 1 has load 1, choose 1


Solve the problem:
Python3
def getMinLoadIndex(n: int, nums: List[int])->List[int]:



Solution







Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.