Code written for fb phone interview