Solution to the CodingBat Array-3 [fix34]
It can easily be done in O(n) i.e a single loop traversal. Think simple .Modify the below program to suit your understanding and find the algorithm in the comments.
Just a brief:


Traverse the array from 0 to get the first position where you meet 3 say curIdx. Now you know that curIdx+1 can be replaced.
Traverse the array from the last to get the last position of 4, say lastIdx. Now you know that lastIdx can be replaced.
Swap curIdx and lastIdx if its within the array's range.

void reArrange(int[] arr)
{

int[] arr = {2, 3, 5, 3, 2, 4, 4};
int lastIdx = arr.length-1;
int curIdx= 0 ;
while(true){ //I know when to exit. Trust me!!!
    // Where art thou my 3. I need to replace the index after you.
    while(curIdx&lt;arr.length &amp;&amp; arr[curIdx]!=3){
        curIdx++;
    }
    curIdx++;

    // Gotcha Mr 4. You need to lead 3 safely.
    while(lastIdx&gt;0 &amp;&amp; arr[lastIdx]!=4){
        lastIdx--;
    }

    // As I said, trust me and I will help you exit
    if(curIdx&gt;=arr.length || lastIdx&lt;=0){
        break;
    }

    // Swap Time to rearrange Mr 4's after 3.
    int temp = arr[curIdx];
    arr[curIdx] = arr[lastIdx];
    arr[lastIdx] = temp;
}

// Did I do it correctly? Lets check.
for(curIdx=0;curIdx&lt;arr.length;curIdx++){
    System.out.print(arr[curIdx] + "  ");
}


}


Note: 


I am rearranging the 4's after 3's without considering the order.
I assume that the input meets the constraints provided.