Computer Science, asked by j5xg8fq5tg, 7 hours ago

A group of people went to a tourist spot. Before entering the place they submitted all their belongings to the management and as an acknowledgement of the same, the management issued a token to each group. Before processing the token number the management collects the details of ages of all the persons in the group as integers. Based on the collected data, the management issues the token number which will be the age of the second oldest person(s). If the group doesn't have a second oldest person then the token number is issued as the age of the oldest person. Write a program to ease this process for the management personnel. Input format: The ages of all the persons in a group as an array of integers. 1st value is array length followed by array values Output format: The age of the second oldest person (or) The age of the oldest person if a second oldest person does not exist in the group. Example 1: Input: A=43221 Output: 2

Answers

Answered by puru079
5

Answer:

what to do in this pls comment

Answered by shilpa85475
10

The ages of all the persons in a group as an array of integers.

1st value is array length followed by array values

Output format: The age of the second oldest person (or) The age of the oldest person if a second oldest person does not exist in the group.

Explanation:

public static Map<Integer,Integer> countAges(int[] ages) {

 if(ages==null || ages.length==0) {

  return new HashMap<Integer,Integer>();

 }

 int i = 0;

 int end = 0;

 Map<Integer,Integer> count = new HashMap<Integer,Integer>();

 int from = 0;

 int to = 0;

 while(i<ages.length) {

  from = i;

  end=binSearchEnd(ages,i,ages.length);

  to = end;

  count.put(ages[i], 1+to-from);

  i=end+1;

 }

 return count;

}

Similar questions