Maximum Width binary tree
In the above code, you missed counting the in-between null nodes, that is why, the result is wrong for the input [2,1,4,3, null,5].

You approached the problem using DFS(Depth First Search) algorithm which is useful to find the height of a tree. 

BFS (Breadth-first search) algorithm would be the best suitable choice for this problem.