AMCAT Automata Fix Sample Question-3

Program 3

Multiple of 3 and 5

 You are required to write the logical part for the function that takes an integer ‘n’ as input and returns a string array ‘answer’ of length ‘n’. Each element ‘answer[i]’ in the array is determined based on the following rules:

If ‘i’ is divisible by both 3 and 5, ‘answer[i]’ should be set to “PrepInsta”.

If ‘i’ is divisible by 3 but not by 5, ‘answer[i]’ should be set to “Prep”.

If ‘i’ is divisible by 5 but not by 3, ‘answer[i]’ should be set to “Insta”.

If none of the above conditions are true, ‘answer[i]’ should be set to the string representation of ‘i’.

5 comments on “AMCAT Automata Fix Sample Question-3”


  • urjas0906

    #include vectorprepInsta(int n) {
    vector st;
    for(int i=1;i<=n;i++){
    if(i%3==0 && i%5==0) st.push_back("PrepInsta");
    else if(i%3==0) st.push_back("Prep");
    else if(i%5==0) st.push_back("Insta");
    else {
    st.push_back(to_string(i));
    }
    }
    return st;
    }


  • samhita162004

    for(int i=1;i<=n;i++){
    if(i%3==0 && i%5==0){
    ans[i-1]="PrepInsta";
    }else if(i%3==0 && i%5!=0){
    ans[i-1]="Prep";
    }else if(i%3!=0 && i%5==0){
    ans[i-1]="Insta";
    }
    else{
    ans[i – 1] = String.valueOf(i);

    }