0% found this document useful (0 votes)
17 views2 pages

Collections Practice2

Uploaded by

Anjali Dani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Collections Practice2

Uploaded by

Anjali Dani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1. WAP in Java to add all the numbers inside a ArrayList.

Sample Input
6
10 20 30 40 50 60

Sample Ouput:
210

===================================================================================
=========================================================================

2. WAP in Java to return the length of the words stored inside in a List as Maps.

Sample Input:
3
apple
banana
cherry

Sample Output:
{"apple":5, "banana":6, "cherry":6}

===================================================================================
=========================================================================

3. Find the intersection of two List and return the result as a List.

Sample Input:
4
1 2 3 4
4
3 4 5 6

Sample Output:
[3, 4]

===================================================================================
=========================================================================

4. Game of Collecting caps


Suppose there are N number if caps in a list of different numbers.
A person has to decide to pick caps of any one number in such a way that he has the
maximum numbers of that cap.

Sample Input:
6
2 3 3 2 4 3

Sample Output:
3

Explanation:
2 Number cap count = 2
3 Number cap count = 3
4 Number cap count = 1

So, the answer is 3 as it has more number of caps.


===================================================================================
=========================================================================

5. Eve runs a small fruit market. She recently received a shipment of fruits
consisting of N fruits where some types may appear multiple times. Each type of
fruit is assigned a unique number (which can be positive or negative).

Write a program to determine how many distinct types of fruits she received, the
count of each fruit type (in descending order of their unique number), and the
ratio of the total number of fruits to the number of distinct types, rounded to the
nearest integer.

Input:

The first line contains an integer N, the total number of fruits in the shipment.
The second line contains N integers representing the unique numbers assigned to the
fruits.

Output:

The first line should contain the number of distinct fruit types.
The following lines should display the frequency of each fruit type, in descending
order of their unique numbers.
The last line should display the ratio of the total fruits to the number of
distinct fruit types, rounded to the nearest integer.

Sample Input:
7
4 -3 4 0 -3 5 0

Sample Output:
4
2
2
2
1
2

You might also like