Skip to content

Commit 16ef9d1

Browse files
committed
issue #26 TwoCharacters-ing
1 parent 20da33a commit 16ef9d1

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/hackerrank/TwoCharacters.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package hackerrank;
2+
/*
3+
The characters present in are a, b, e, and f.
4+
This means that must consist of two of those characters and we must delete two others.
5+
Our choices for characters to leave are [a,b], [a,e], [a, f], [b, e], [b, f] and [e, f].
6+
If we delete e and f, the resulting string is babab.
7+
This is a valid as there are only two distinct characters (a and b),
8+
and they are alternating within the string.
9+
If we delete a and f, the resulting string is bebeeeb.
10+
This is not a valid string because there are consecutive e's present.
11+
Removing them would leave consecutive b's, so this fails to produce a valid string .
12+
Other cases are solved similarly.
13+
babab is the longest string we can create.
14+
*/
15+
public class TwoCharacters {
16+
static int alternate(String s) {
17+
18+
19+
}
20+
21+
public static void main(String[] args) {
22+
System.out.println(alternate("beabeefeab")+", ans: 5");
23+
}
24+
}

0 commit comments

Comments
 (0)