I couldn't find any BFS solution in Java, so here you go.

Main idea: The number of levels BFS traverses in the graph to reach n, is the solution.

```
class Solution {
public int numSquares(int n) {
//A regular queue
Queue<Integer> queue = new LinkedList<Integer>();
queue.offer(0);
int levels = 0;
while(!queue.isEmpty()){
int size = queue.size();
// This loop helps us keep track of levels
while(size-- > 0){
int x = queue.poll();
// push only those values which do not exceed n
for(int i=n; i>0; i--){
if ((x + i*i) == n) return levels + 1;
else if((x + i*i) < n) queue.offer(x+i*i);
}
}
levels ++;
}
return levels;
}
}
```