DEV Community

Rajesh
Rajesh

Posted on

I found this problem in tcs nqt mock test, I cannot still figure it out question!!

TCS NQT Practice Test - IT

Question Paper
Section
Advanced Coding - 1
Note :You need to press "Final Submit" for your program to be considered for evaluation. The program will NOT be auto-submitted in case your exam is auto-closed due to time out.

John is hosting a celebration for the grand opening of his new startup and has invited all of his N colleagues. Each colleague is assigned a unique index from 1 to N, and they are known to each other by their respective salaries, represented by integer values. John needs to arrange tables to accommodate everyone, but he wants to do so while minimizing costs. Each table has a seating capacity, and renting each table costs K. However, there's a concern that colleagues with the same salary might get into arguments if seated together.

To minimize costs and avoid conflicts, John wants to find the optimal arrangement with the smallest possible inefficiency. Inefficiency here is defined as the sum of the cost of tables plus the total number of people involved in conflicts. Given the number of colleagues, N, and their salaries represented by array s[], John seeks to determine the optimal inefficiency.

Sample Input:

5,1000,1500,1200,1000,1000,1

When the above line is given as sample input,

N = 5

Salaries: [1000, 1500, 1200, 1000, 1000]

Cost of each table, K = 1

Sample Output:

3

Explanation:

Given 5 colleagues with salaries [1000, 1500, 1200, 1000, 1000] and a cost of renting each table, K = 1, the optimal arrangement is as follows:

Table 1: Colleague 1 (salary 1000), Colleague 4 (salary 1000), and Colleague 5 (salary 1000)

Table 2: Colleague 3 (salary 1200)

Table 3: Colleague 2 (salary 1500)

Total inefficiency = Cost of renting tables + Number of people in conflicts

= (3 * 1) + 0

= 3 + 0

= 3

Thus, the optimal inefficiency is 3.

Your code should read the inputs in the format given by the Sample Input and print the optimal inefficiency

Note: Your Code will be evaluated against 10 test cases and you will be given 1 mark each for every passed test case

Test Case: 1

Input

10,1000,1500,1200,1000,1000,2000,1200,1500,500,7000,1

Output

5

Test Case: 2

Input

10,1000,1500,1200,1000,1000,2000,1200,1500,500,7000,2

Output

7

Test Case: 3

Input

8,100,100,100,200,1200,1500,500,7000,1

Output

3

Test Case: 4

Input

8,100,100,100,200,1200,1500,500,7000,2

Output

5

Test Case: 5

Input

9,100,100,100,200,120,150,500,700,100,2

Output

6

Test Case: 6

Input

9,100,100,100,200,120,150,500,700,100,1

Output

4

Test Case: 7

Input

8,100,100,200,120,150,500,700,100,1

Output

3

Test Case: 8

Input

8,100,100,200,120,15,50,70,10,1

Output

2

Test Case: 9

Input

8,100,100,200,120,15,50,70,10,2

Output

4

Test Case: 10

Input

8,10,200,200,120,15,50,70,10,1

Output

3

Program Editor

Choose programming Language :

Java
Custom Inputs
Compile Code
View Solution
Next
Previous
John is hosting a celebration for the grand opening of his new startup and has invited all of his N colleagues. Each colleague is assigned a unique index from 1 to N, and they are known to each other by their respective salaries, represented by integer values. John needs to arrange tables to accommodate everyone, but he wants to do so while minimizing costs. Each table has a seating capacity, and renting each table costs K. However, there's a concern that colleagues with the same salary might get into arguments if seated together.

To minimize costs and avoid conflicts, John wants to find the optimal arrangement with the smallest possible inefficiency. Inefficiency here is defined as the sum of the cost of tables plus the total number of people involved in conflicts. Given the number of colleagues, N, and their salaries represented by array s[], John seeks to determine the optimal inefficiency.

Sample Input:

5,1000,1500,1200,1000,1000,1

When the above line is given as sample input,

N = 5

Salaries: [1000, 1500, 1200, 1000, 1000]

Cost of each table, K = 1

Sample Output:

3

Explanation:

Given 5 colleagues with salaries [1000, 1500, 1200, 1000, 1000] and a cost of renting each table, K = 1, the optimal arrangement is as follows:

Table 1: Colleague 1 (salary 1000), Colleague 4 (salary 1000), and Colleague 5 (salary 1000)

Table 2: Colleague 3 (salary 1200)

Table 3: Colleague 2 (salary 1500)

Total inefficiency = Cost of renting tables + Number of people in conflicts

= (3 * 1) + 0

= 3 + 0

= 3

Thus, the optimal inefficiency is 3.

Your code should read the inputs in the format given by the Sample Input and print the optimal inefficiency

Note: Your Code will be evaluated against 10 test cases and you will be given 1 mark each for every passed test case

Test Case: 1

Input

10,1000,1500,1200,1000,1000,2000,1200,1500,500,7000,1

Output

5

Test Case: 2

Input

10,1000,1500,1200,1000,1000,2000,1200,1500,500,7000,2

Output

7

Test Case: 3

Input

8,100,100,100,200,1200,1500,500,7000,1

Output

3

Test Case: 4

Input

8,100,100,100,200,1200,1500,500,7000,2

Output

5

Test Case: 5

Input

9,100,100,100,200,120,150,500,700,100,2

Output

6

Test Case: 6

Input

9,100,100,100,200,120,150,500,700,100,1

Output

4

Test Case: 7

Input

8,100,100,200,120,150,500,700,100,1

Output

3

Test Case: 8

Input

8,100,100,200,120,15,50,70,10,1

Output

2

Test Case: 9

Input

8,100,100,200,120,15,50,70,10,2

Output

4

Test Case: 10

Input

8,10,200,200,120,15,50,70,10,1

Output

3

Top comments (0)