← Capital One Interview Insights

Capital One·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Capital One software engineer interview with a calendar/date math problem that seems deceptively simple but has a bunch of edge cases hiding in it. Nothing too wild on the process side, just the one coding problem.

Questions Asked (1)

Q1

Given the moon's state on the first day of a year (cycling through 8 states over 8 days), write a function that returns the moon's state on a given target month and day. Your solution must correctly handle the number of days in each month and leap years.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The core logic is just counting total days elapsed from Jan 1 and doing modulo 8, but I spent way too long second-guessing whether the start day counted as day 0 or day 1.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, compute the total number of days elapsed from the start of the year to the target date, accounting for month lengths and leap years. Then, use modulo 8 on the total days (since the moon cycles every 8 days) to find the index in the given 8-state cycle, adjusting for whether the first day is day 0 or day 1.

Pro tip: Clarify with the interviewer whether the first day of the year is considered day 0 or day 1, as this off-by-one error is a common pitfall. Also, mention that you can precompute cumulative days for each month to avoid repeated calculations.

1. Clarify assumptions and edge cases

Confirm the input format (e.g., month as integer 1-12, day as integer), the starting state (e.g., state 0 on Jan 1), and whether the year is provided or fixed. Ask about leap year rules (e.g., Gregorian calendar).

2. Compute days elapsed

Calculate the total number of days from the start of the year to the target date. Sum the days in all full months before the target month, then add the target day. Adjust February for leap years if the year is given or assumed.

3. Apply modulo to find state

Since the moon cycles every 8 days, take the total days elapsed modulo 8. If the first day is state 0, the state is (total_days) % 8; if the first day is state 1, it's (total_days - 1) % 8 + 1, etc. Ensure the result maps to the correct index in the 8-state array.

4. Handle leap years correctly

If the year is provided, determine if it's a leap year (divisible by 4, except centuries unless divisible by 400). Add 1 to February's days if leap year and the target month is after February.

5. Test with edge cases

Test with dates like Jan 1 (should return initial state), Dec 31 (end of year), leap day (Feb 29), and dates in leap vs non-leap years to verify correctness.

Key Points to Mention

  • Modulo arithmetic to map days to the 8-state cycle
  • Leap year rules (divisible by 4, not by 100 unless by 400)
  • Cumulative days per month or a lookup table for month lengths
  • Off-by-one error: whether day 1 is state 0 or state 1
  • Time and space complexity: O(1) time with precomputed month days, O(1) space
  • Edge cases: leap day, year boundaries, invalid inputs

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.