I was interviewed at microsoft and at that time i was not able to code this solution, but when i tried afterwards i was able to .
so the question was.
you are give 3 integers aa=5 , ab=0 ,bb=2.
you have to use 3 string "AA" , "AB" and "BB"
we need to create a string of maximum length where the string concetation should not create "AAA"
or "BBB" together.
Attaching the solution for the problem, which i solved.
anyone who want update the approach is welcomed.
public class MyClass {
public static void main(String args[]) {
//aa ab bb
System.out.println(sol(9,0,5));
}
public static String sol(int A, int B,int C) {
StringBuilder res = new StringBuilder();
int i = A, j = B, k = C;
String str="";
//3-2-1
while (i>0&&j>0&&k>0) {
if(i>k && i>j){
str+="AABBAB";
i--;j--;k--;
}else if(j>i &&j>k){
str+="ABAABB";
i--;j--;k--;
}else{
str+="BBABAA";
i--;j--;k--;
}
}
if(i==0){
while(j>0 && k>0){
str+="BBAB";
j--;k--;
}
if(j!=0){
if(str.isEmpty()){
str+="AB";
j--;
}{
while(j>0 && str.charAt(str.length()-1)!='A'){
str+="AB";
j--;
}
}
}
if(k!=0){
if(str.isEmpty()){
str+="BB";
k--;
}
while(k>0 && str.charAt(str.length()-1)!='B'){
str+="BB";
k--;
}
}
}if(j==0){
while(i>0&&k>0){
str+="AABB";
i--;k--;
}if(i>0 && !str.isEmpty() && str.charAt(str.length()-1)!='A' ){
str+="AA";
i--;
}
}if(k==0){
while(j>0&&i>0){
str+="ABAA";
j--;i--;
}
}
return str;
}
}


