-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllSubArrayOfKLength.java
More file actions
66 lines (53 loc) · 1.61 KB
/
Copy pathAllSubArrayOfKLength.java
File metadata and controls
66 lines (53 loc) · 1.61 KB
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
63
64
65
66
package com.samsung;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
public class AllSubArrayOfKLength {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = 5;
int k = 3;
int a[]= {1,2,3,4,5};
int sub[]=new int[k];
/*for(int i = 0 ; i < n; ++i) {
a[i]=Integer.parseInt(br.readLine());
}*/
subarray(a, n , sub, k, 0, 0,0);
}
static void subarray(int a[], int n, int sub[], int r, int i, int j,int sum)
{
if(j == r) /* current index of sub r, print sub */
{
Map<Integer,Integer> countMap=new HashMap<Integer,Integer>();
for(int k=0;k<r;k++) {
if(countMap.containsKey(sub[k])) {
countMap.put(sub[k], countMap.get(sub[k])+1);
}else {
countMap.put(sub[k],1);
}
}
for(Entry<Integer, Integer> map : countMap.entrySet()) {
if(map.getValue()%2!=0) {
}
}
/*int k;
System.out.print("( ");
for(k = 0; k < r; k++)
System.out.print(sub[k]);
System.out.println(")");*/
}
else
{
if(i < n)
{
sub[j] = a[i];
subarray(a, n, sub, r, i + 1, j + 1,sum); /* Include current element */
subarray(a, n, sub, r, i + 1, j,sum); /* Override the current element */
}
}
}
}