-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem-Code
62 lines (48 loc) · 1.37 KB
/
Problem-Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//Initial Template for Java
import java.io.*;
import java.util.*;
// } Driver Code Ends
//User function Template for Java
class Solution{
public static ArrayList<Integer> RopeCutting (int arr[], int n) {
Arrays.sort(arr);
ArrayList<Integer> al=new ArrayList<>();
int c=1,m=n;
for(int i=0 ; i<n-1 ; i++){
if(arr[i]==arr[i+1])
c++;
else if(arr[i]!=arr[i+1]){
m=m-c;
al.add(m);
c=1;
}
}
return al;
}
}
//{ Driver Code Starts.
class GFG {
// Driver code
public static void main (String[] args) throws IOException{
// Taking input using buffered reader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcases = Integer.parseInt(br.readLine());
// looping through all testcases
while(testcases-- > 0){
int sizeOfArray = Integer.parseInt(br.readLine());
int arr [] = new int[sizeOfArray];
String line = br.readLine();
String[] elements = line.trim().split("\\s+");
for(int i = 0;i<sizeOfArray;i++){
arr[i] = Integer.parseInt(elements[i]);
}
Solution obj = new Solution();
ArrayList<Integer> res;
res = obj.RopeCutting(arr, sizeOfArray);
for(int i: res)
System.out.print(i + " ");
System.out.println();
}
}
}
// } Driver Code Ends