Dsa
Two Pointers
Medium
Balanced Partitioning
You are given an array of integers representing the weights of various items. Your task is to determine the minimum number of partitions such that the sum of weights in each partition is equal. You must create at least one partition, and each item's weight must belong to exactly one partition. If it is impossible to partition the array this way, return -1.
Input format:
- A single line containing N (1 ≤ N ≤ 100000), the number of elements in the array.
- A second line containing N integers, each representing an element of the array.
Output format:
- A single integer indicating the minimum number of partitions possible, or -1 if impossible.
Example:
Input:
6
3 1 1 2 2 3
Output:
3
Key concepts
two_pointersgreedyprefix_sums
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now