-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountStarsIbm.java
More file actions
61 lines (46 loc) · 1.37 KB
/
countStarsIbm.java
File metadata and controls
61 lines (46 loc) · 1.37 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
/**
* @author kaitavmehta created on 2020-02-16
*/
// compiler design test- requires optimization
// do mutiple star search in one loop
public class countStarsIbm {
public static int helperFunction(String s, int start, int end) {
// check for |
// count // even pe delete
start = start - 1;
int validCount = 0;
boolean inZone = false;
char pipe = '|';
char star = '*';
int rangeCount = 0;
for (int i = start; i < end; i++) {
if (s.charAt(i) == pipe) {
if (inZone) {
inZone = false;
validCount = validCount + rangeCount;
}
// false- true
if (!inZone) {
inZone = true;
}
rangeCount = 0;
}
if (inZone && s.charAt(i) == star) {
rangeCount = rangeCount + 1;
}
}
return validCount;
}
public static void main(String args[]) {
System.out.println("");
String s = "|**|*|*";
int[] startIndex = {1, 1};
int[] endIndex = {4, 3};
int n = 1; // min size
int count = 0;
for(int i =0; i< n; i++) {
count = count + helperFunction(s, startIndex[i], endIndex[i]);
}
System.out.println(count);
}
}