← Capital One Interview InsightsSoftware Engineer

Capital One·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Capital One SWE interview with a calendar/date logic problem that looks deceptively simple but has a bunch of edge cases hiding in it. Pretty standard technical screen vibe.

Questions Asked (1)

Q1

The moon cycles through 8 states (0 to 7) over 8 days. Given the moon's state on January 1st and a target date (month and day), return the moon's state on that date. Your solution needs to handle the correct number of days per month and leap years.

Algorithms & Data Structures
Author's notes

My first instinct was to just count days elapsed from Jan 1 and mod by 8.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases, then design a solution that computes the number of days between January 1st and the target date, handling leap years correctly. Use the day difference modulo 8 to find the moon's state, ensuring the calculation accounts for the starting state.

Pro tip: Mention that you would use a well-tested date library or implement a leap year check (divisible by 4, except centuries not divisible by 400) to avoid off-by-one errors. Also, discuss how you would test edge cases like leap days and year boundaries.

1. Clarify requirements and edge cases

Ask about input format, range of years, and whether the target date is always after January 1st. Confirm the moon state cycle and how to handle invalid dates.

2. Compute days elapsed

Calculate the number of days from January 1st to the target date, including leap year adjustments. Use cumulative days per month or a date library.

3. Apply modulo arithmetic

Compute (initial_state + days_elapsed) % 8 to get the moon state on the target date. Ensure the result is in the range 0-7.

4. Handle leap years correctly

Implement a leap year function: year % 4 == 0 and (year % 100 != 0 or year % 400 == 0). Adjust February days accordingly.

5. Test and validate

Test with edge cases: same day (0 days elapsed), leap day, year boundary, and different starting states. Verify with manual calculations.

Key Points to Mention

  • Leap year rules: divisible by 4, except centuries unless divisible by 400.
  • Cumulative days per month array, with February adjusted for leap years.
  • Modulo operation to cycle through 8 states.
  • Handling of January 1st as day 0 (no days elapsed).
  • Potential off-by-one errors in date calculations.
  • Time and space complexity: O(1) time, O(1) space.

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