Make S into an alternate binary string by changing any character with 0 or 1 as much as Okay instances

import
java.util.*;
public
class
GFG {
public
static
void
essential(String[] args)
{
String str =
"akmzaxazmk"
;
int
Okay =
6
;
AlterString(str, Okay);
}
static
void
AlterString(String str,
int
Okay)
{
boolean
flag =
true
;
HashMap<Character, Integer> map =
new
HashMap<>();
for
(
int
i =
0
; i < str.size(); i++) {
if
(map.containsKey(str.charAt(i))) {
int
finish = map.get(str.charAt(i));
if
((finish - i) %
2
==
0
) {
proceed
;
}
else
{
flag =
false
;
break
;
}
}
else
{
map.put(str.charAt(i), i);
}
}
if
(flag && map.measurement() <= Okay) {
System.out.println(
"YES"
);
for
(Map.Entry<Character, Integer> set :
map.entrySet()) {
System.out.println(
" "
+ set.getKey() +
" : "
+ ((set.getValue() %
2
==
0
) ?
0
:
1
));
}
}
else
{
System.out.println(
"NO"
);
}
}
}