Adding non-BFS solution for populating next right pointer