The Joy of Computing using Python Week 12: Programming Assignment - Jun-Dec 2021

  NPTEL PROGRAMMING ASSIGNMENTS


The Joy of Computing using Python


Week 12: Programming Assignment 1 - Candies

Due on 2021-10-21, 23:59 IST

Prof. S is on a trip with a set of students from his course. He has several packets of

candies to be distributed among the students. Unfortunately, the sizes of the packets are

not the same and the professor would like to distribute the candies in an unbiased way. A

solution is to open all the packets and move some candies from the larger packets to the

smaller ones so that each packet contains an equal number of candies. Your task is to

determine the minimum number of such moves to ensure all packets have the same

number of candies.

Input Format be like

The first line of the input contains space separated integers indicating the sizes of each

packet

Output Format must be like

Display a single integer indicating the minimum number of moves required to equalise the size of each packet.

If it is not possible to equalise, display -1 as output.

For Example:

If Input is

1 1 1 1 6

Then Output must be

4

Or Input is

2 3 4

Than Output must be

-1

  

Week12: Programming Assignment 2 - Suitcases

Due on 2021-10-21, 23:59 IST

Four persons A, B, C and D are on a trip. Each of the four have one square shaped suitcase with them. They want to pack their suitcases into a large square box. The suitcases and the large box are cuboids with a square base and the heights of the large box as well as the four suitcases are exactly the same. Hence the concern is only about the side (length) of the large square box. Your task is to find the minimum length of the large square box so that all the four suitcases can be put into the box without any overlapping.


Input Format is

The first line of the input contains four space separated integers indicating the lengths of the suitcases of A, B, C and D respectively

Then Output Format must be

Display a single integer indicating the length of the large square box required

For Example:

If Input is

2 2 2 2

Then Output must be

4

 

Week12: Programming Assignment 3 - Game of Strengths

Due on 2021-10-21, 23:59 IST

Krishna and Balarama are playing a game of strength. There are n walls arranged in a linear fashion and each wall has a strength value associated with it (the value is guaranteed to be distinct for each wall). The strength value indicates the amount of strength required to break a wall. The breaking of walls must be done only from the ends and any intermediate wall cannot be broken. The first one to break both the walls - one having the least value and the other with the highest value wins the game. Balarama, using his brute force, decides to knock off the walls one by one in a random fashion as he knows they would tumble down easily to his sheer strength. Krishna, on the other hand, decides to calculate the least number of walls to be knocked to achieve a win. Can you help Krishna to compute the minimum number of walls to be knocked?

For example,

If n = 6, with strength values : 1 4 5 3 6 2

It requires a minimum 3 knocks to achieve a win.

(One knock from the left end and two knocks from the right end)


Input Format be Like

The first line contains an integer t indicating the number of test cases.

Next t test cases follow.

The first line of each test case contains one integer n — the number of walls.

The second line of test case contains n distinct integers a1, a2, . . ., an (indicating the strength value for each wall)

Constraints

1 ≤ t ≤ 100

2 ≤ n ≤ 100

 

Output Format be Like

For each test case, output the minimum number of walls to be knocked to win the game.

For Example If

Input is

3

5

1 3 4 5 2

8

12 11 13 14 15 16 18 17

4

3 2 4 1

Then Output must be

3

4

2

  


Post a Comment (0)
Previous Post Next Post