It is recommendable that you reside in the United States three months prior to filing your N-400 application, in order to ensure jurisdiction of your local office. After filing, you are free to leave the country on normal vacations, etc. but you may not be outside of the country for 6 months. It is also important to keep in mind that you will receive notices from CIS like a fingerprint appointment, interview appointment, etc. that will need your prompt attention and physical presence. Good luck!