Tap here to switch tabs
Problem
Submissions

Problem: Assign Elements to Groups with Constraints

med
30 min
Try to solve the Assign Elements to Groups with Constraints problem.

Statement

You are given an integer array groups, where each element represents the size of a group, and an integer array elements.

For each group groups[i], assign the smallest index j such that elements[j] divides groups[i] with a remainder of 00. If no such element exists, assign −1-1 to that group.

Return an integer array assigned of the same length as groups, where assigned[i] represents the index of the element assigned to groups[i].

Constraints:

  • 1≤1 \leq groups.length ≤105\leq 10^5

  • 1≤1 \leq elements.length ≤105\leq 10^5

  • 1≤1 \leq groups[i] ≤105\leq 10^5

  • 1≤1 \leq elements[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Assign Elements to Groups with Constraints

med
30 min
Try to solve the Assign Elements to Groups with Constraints problem.

Statement

You are given an integer array groups, where each element represents the size of a group, and an integer array elements.

For each group groups[i], assign the smallest index j such that elements[j] divides groups[i] with a remainder of 00. If no such element exists, assign −1-1 to that group.

Return an integer array assigned of the same length as groups, where assigned[i] represents the index of the element assigned to groups[i].

Constraints:

  • 1≤1 \leq groups.length ≤105\leq 10^5

  • 1≤1 \leq elements.length ≤105\leq 10^5

  • 1≤1 \leq groups[i] ≤105\leq 10^5

  • 1≤1 \leq elements[i] ≤105\leq 10^5