← Boston Consulting Group Interview Insights
Took me a minute to even parse what they were asking.
First, clarify the problem constraints: whether the year is a leap year, how to handle month lengths, and the exact phase names. Then, compute the total number of days from January 1st to the target date, add the offset of the given moon phase on January 1st, and take modulo 8 to find the new phase index.
Pro tip: Mention edge cases like leap years and validate with a simple example (e.g., January 1st itself) to show thoroughness. Also, discuss how you would extend the solution to handle varying cycle lengths or real astronomical data.
Confirm the year (to determine leap year), the phase names and their order, and whether the given phase on Jan 1 is an index or name. Establish that standard month lengths are used, but leap years affect February.
Assign each of the 8 phases a numerical index (e.g., 0 to 7) in a consistent order, such as New Moon=0, Waxing Crescent=1, etc. This allows modular arithmetic.
Calculate the total number of days from January 1st to the target date. Use an array of cumulative days per month, adjusting for leap year if necessary. Subtract 1 if counting from Jan 1 as day 0, or keep as is if Jan 1 is day 1.
Add the days elapsed to the initial phase index, then take modulo 8. This gives the new phase index. Map back to the phase name.
Test with simple cases (e.g., same date, next day) and discuss handling of leap years, invalid dates, and potential extensions like using real lunar cycle data.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.