All Problems

Problem title

Difficulty

Avg time to solve

Split Array Into Fibonacci Sequence

Moderate

15 mins

Minimum insertions.

Hard

45 mins

Maximum Nesting Depth Of Two Valid Parentheses Strings

Moderate

30 mins

Find Valid Matrix

Moderate

30 mins

Minimum Costs Of Subsets

Hard

15 mins

Toss Strange Coins

Easy

15 mins

Ninja's Contract

Hard

45 mins

Ninja And Divisible Array

Moderate

15 mins

Create Lexicographically Greatest Array

Hard

45 mins

Car Pooling

Moderate

30 mins

Problem

Submissions

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
1. Each element in ARR belongs to exactly one subset.
2. All the elements in a subset are unique.
3. Each subset has a size of ‘N’/ ’K’
```

```
[1,2,3,1,2,5] k=2
[[1,2,3],[1,2,5]] is a valid subset division. All the elements in each subset are unique and the the cost of construction is (3 - 1) + (5 - 1) = 6
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line and the only line of each test case contain two single space-separated integers, ‘N’ and ‘K’.
The second line of each test case contains N space-separated integers representing the elements of the array ARR.
```

```
For each test case print the minimum cost of construction.
Output for each test case is printed in a separate line.
```

```
You don’t need to print anything. It has already been taken care of. Just implement the given function.
```

```
1 <= T <= 5
1 <= N <= 12
1 <= K <= N
1<= ARR[i] <= 20
K is a devisor of the N
Time Limit: 1 sec
```

```
2
4 2
1 4 5 9
5 5
1 2 3 4 5
```

```
7
0
```

```
For the first test case [[1,4], [5,9]] is the required distribution.
ANS = ( 4 - 1) + (9 - 5) = 7
[ [1, 5], [9, 4] ] is also the valid distribution but the cost of construction is not minimum.
For the second test case each subset has exactly one element [ [1], [2], [3], [4], [5] ]
ANS = (1 - 1) + (2 - 2) + (3 - 3) + (4 - 4) + (5 - 5)
```

```
2
6 3
3 3 3 1 11 4
4 2
7 11 7 11
```

```
11
8
```

Java (SE 1.8)

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Theme

Solution submission not allowed

Save Code

Reset Code