-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashing.java
More file actions
32 lines (23 loc) · 747 Bytes
/
Hashing.java
File metadata and controls
32 lines (23 loc) · 747 Bytes
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
import java.util.Scanner;
public class Hashing {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] arr = {3,3,4,5,6,3,2};
// precompute
int[] hash = new int[13];
for (int i = 0; i < arr.length; i++) {
hash[arr[i]] += 1;
System.out.print(arr[i]);
}
// Read number of queries
System.out.print("Enter number of queries: ");
int q = sc.nextInt();
while (q-- > 0) {
System.out.print("Enter number to check: ");
int number = sc.nextInt();
// fetch
System.out.println("Count: " + hash[number]);
}
sc.close();
}
}