Skip to content

Commit 4ab10ff

Browse files
committed
added
1 parent e76840a commit 4ab10ff

File tree

6 files changed

+141
-8
lines changed

6 files changed

+141
-8
lines changed

Linked List/LinkedList.class

1.29 KB
Binary file not shown.

Linked List/LinkedList.java

Lines changed: 0 additions & 8 deletions
This file was deleted.

Linked List/Main.class

977 Bytes
Binary file not shown.

Linked List/Main.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import java.util.*;
2+
class Node<T>{
3+
T data;
4+
Node<T> next;
5+
}
6+
class LinkedList<T> {
7+
Node<T> head;
8+
Node<T> tail;
9+
int size;
10+
11+
void add(T value){
12+
Node<T> temp = new Node<>();
13+
temp.data = value;
14+
temp.next = null;
15+
if (size == 0){
16+
head = tail = temp;
17+
}
18+
19+
else{
20+
tail.next = temp;
21+
tail = temp;
22+
}
23+
size++;
24+
}
25+
int size(){
26+
return size;
27+
}
28+
29+
void display(){
30+
Node<T> temp = head;
31+
while(temp!= null){
32+
System.out.print(temp.data+" ");
33+
temp = temp.next;
34+
}
35+
}
36+
37+
void removeFirst(){
38+
if (head == null){
39+
System.out.println("List is empty");
40+
}
41+
else{
42+
head = head.next;
43+
size--;
44+
}
45+
}
46+
47+
<T> Object getAt(Node<T> head){
48+
return T;
49+
}
50+
51+
52+
}
53+
54+
public class Main{
55+
public static void main(String[] args) {
56+
int arr[] = {1,2,3,4,5,6,7,8,9};
57+
LinkedList<Integer> ll = new LinkedList<>();
58+
for(int i=0;i<arr.length;i++){
59+
ll.add(arr[i]);
60+
}
61+
ll.display();
62+
System.out.println("\n"+ll.size());
63+
ll.removeFirst();
64+
ll.display();
65+
}
66+
}

Linked List/Node.class

341 Bytes
Binary file not shown.

check

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* package codechef; // don't place package name! */
2+
3+
import java.util.*;
4+
import java.lang.*;
5+
import java.io.*;
6+
7+
/* Name of the class has to be "Main" only if the class is public. */
8+
class Codechef
9+
{ static HashMap<Long, Long> sortByValue(HashMap<Long, Long> hm)
10+
{
11+
// Create a list from elements of HashMap
12+
List<Map.Entry<Long, Long> > list =
13+
new LinkedList<Map.Entry<Long, Long> >(hm.entrySet());
14+
15+
// Sort the list
16+
Collections.sort(list, new Comparator<Map.Entry<Long, Long> >() {
17+
public int compare(Map.Entry<Long, Long> o1,
18+
Map.Entry<Long, Long> o2)
19+
{
20+
return (o1.getValue()).compareTo(o2.getValue());
21+
}
22+
});
23+
24+
// put data from sorted list to hashmap
25+
HashMap<Long, Long> temp = new LinkedHashMap<Long, Long>();
26+
for (Map.Entry<Long, Long> aa : list) {
27+
temp.put(aa.getKey(), aa.getValue());
28+
}
29+
return temp;
30+
}
31+
static long minChec(long arr[] , long arr2[], int n ){
32+
HashMap<Long, Long> mp = new HashMap<>();
33+
for (int i = 0;i<n ;i++ ){
34+
if(mp.containsKey(arr[i])){
35+
mp.put(arr[i], mp.get(arr[i])+1);
36+
}
37+
else{
38+
mp.put(arr[i],1);
39+
}
40+
}
41+
for (int i = 0;i<n ;i++ ){
42+
if(mp.containsKey(arr2[i])){
43+
mp.put(arr2[i], mp.get(arr2[i])+1);
44+
}
45+
else{
46+
mp.put(arr2[i],1);
47+
}
48+
}
49+
HashMap<, Long> hm = sortByValue(mp);
50+
for(Long i : hm.keySet()){
51+
System.out.print(i+" ");
52+
}
53+
return 0;
54+
55+
}
56+
public static void main (String[] args) throws java.lang.Exception
57+
{
58+
// your code goes here
59+
Scanner sc = new Scanner(System.in);
60+
int t = sc.nextInt();
61+
while(t>0){
62+
int n = sc.nextInt();
63+
long arr[] = new long[n];
64+
long ar2[] = new long[n];
65+
for (int i = 0 ; i <n; i++){
66+
arr[i] = sc.nextLong();
67+
}
68+
for (int i = 0 ; i <n; i++){
69+
ar2[i] = sc.nextLong();
70+
}
71+
System.out.println(minChec(arr, ar2, n));
72+
t--;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)