Computer Science, asked by candy108, 1 year ago

Bottle Necks
-- Problem Description
There are N bottles. ith bottle has A[i] radius. Once a bottle is enclosed inside another bottle, it ceases to be visible. Minimize the number of visible bottles.
You can put ith bottle intojth bottle if following condition is fulfilled:
1) ith bottle itself is not enclosed in another bottle.
2) jth bottle does not enclose any other bottle.
3) Radius of bottle i is smaller than bottlej (ie. A[i] <A[]).
- Constraints
1<= N<= 100000
1 <= A[i] <= 10^18
Input Format
First line contains a single integer N denoting the number of bottles.
Second line contains N space separated integers, ith integer denoting the radius of Ith bottle.
(1<=i<= N).
- Output
Minimum number of visible bottles.
- Test Case
- Explanation
Example 1
Input
co
BL
e
6
*
$
9 O
f​

Answers

Answered by vishald295
0

Answer:

import java.util.*;

class BottleNeck{

public static void main(String args[]){

 Scanner sc = new Scanner(System.in);

 int size = sc.nextInt();

 long num;

 int count = 0;

 List<Long> al = new ArrayList<Long>();

 TreeSet<Long> tr = new TreeSet<Long>();

 for(int i = 0 ; i < size ; i++){

  num = sc.nextLong();

  al.add(num);

  tr.add(num);

 }

 while(al.size() > 0){

  while(tr.size() > 0)

  {

   num = tr.first();

   tr.remove(num);

   al.remove(new Long(num));

  }

  count++;

  for(int i = 0 ; i < al.size() ; i++)

  {

   tr.add(al.get(i));

  }

 }

 System.out.println(count);

}

}

Explanation:

Similar questions