Home Interview Master Calendar and Clock Problems for Aptitude Interviews
Intermediate 4 min · July 13, 2026

Master Calendar and Clock Problems for Aptitude Interviews

Learn to solve calendar and clock problems with formulas, tricks, and code examples.

N
Naren Founder & Principal Engineer

20+ years shipping production code across the stack, with years spent interviewing engineers. Lessons pulled from things that broke in production.

Follow
Production
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
Before you start⏱ 15-20 min read
  • Basic arithmetic and modular arithmetic
  • Understanding of time (hours, minutes)
  • Familiarity with leap year rules
 ● Production Incident 🔎 Debug Guide ⚙ Triage Commands
Quick Answer
  • Calendar problems rely on odd days and modular arithmetic.
  • Clock problems involve relative speed and angle calculations.
  • Key formulas: angle = |30H - 5.5M|, odd days count modulo 7.
  • Practice with real interview questions to build speed.
  • Use code to verify answers, but focus on mental math.
✦ Definition~90s read
What is Calendar and Clock Problems?

Calendar and clock problems are aptitude questions that test your ability to compute days of the week, angles between clock hands, and times of coincidence using modular arithmetic and relative motion concepts.

Think of a calendar like a repeating pattern of days.
Plain-English First

Think of a calendar like a repeating pattern of days. If you know what day it is today, you can figure out any future or past date by counting how many days have passed and taking the remainder when divided by 7. Clocks are like two runners on a circular track: the hour hand is slow, the minute hand is fast, and they meet at specific times. The angle between them is like the distance between the runners.

Calendar and clock problems are a staple in aptitude tests and technical interviews, especially for roles that require logical reasoning and quick mental math. They test your ability to handle modular arithmetic, relative motion, and pattern recognition. In real-world scenarios, these concepts appear in scheduling algorithms, time zone conversions, and even in designing countdown timers. In interviews, you'll often be asked to compute the day of the week for a given date or the angle between clock hands at a specific time. This article will equip you with the essential formulas, tricks, and coding solutions to tackle these problems confidently. We'll cover odd days, leap years, relative speed of clock hands, and common pitfalls. By the end, you'll be able to solve these problems in seconds and explain your reasoning clearly.

Understanding Odd Days and Leap Years

The foundation of calendar problems is the concept of odd days. An ordinary year has 365 days, which is 52 weeks and 1 odd day. A leap year has 366 days, i.e., 52 weeks and 2 odd days. To find the day of the week for a given date, we calculate the total number of odd days from a reference date (e.g., January 1, 0001, which is assumed to be Monday). The day of the week is determined by the remainder when total odd days are divided by 7: 0 = Sunday, 1 = Monday, ..., 6 = Saturday. Leap years are divisible by 4, but century years must be divisible by 400 to be leap. For example, 1900 is not a leap year, but 2000 is. Memorize the odd days for months: Jan=3, Feb=0/1 (leap), Mar=3, Apr=2, May=3, Jun=2, Jul=3, Aug=3, Sep=2, Oct=3, Nov=2, Dec=3. Alternatively, use the mnemonic: 'Add 3 for Jan, 0/1 for Feb, 3 for Mar...'

odd_days.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def day_of_week(day, month, year):
    # Zeller's congruence or simple odd days method
    # Reference: 01/01/0001 = Monday (odd days = 1)
    # Count years
    years = year - 1
    odd_days = (years * 365 + years // 4 - years // 100 + years // 400) % 7
    # Add days of months
    month_days = [0, 3, 0, 3, 2, 3, 2, 3, 3, 2, 3, 2, 3]
    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
        month_days[2] = 1  # February in leap year
    for m in range(1, month):
        odd_days = (odd_days + month_days[m]) % 7
    odd_days = (odd_days + day) % 7
    days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    return days[odd_days]

print(day_of_week(1, 1, 2024))  # Monday
Output
Monday
💡Memory Aid
📊 Production Insight
In production, always use established libraries like Python's datetime or Java's Calendar to avoid manual errors.
🎯 Key Takeaway
Master odd days and leap year rules to quickly compute any day of the week.

Calendar Formulas and Shortcuts

For competitive exams, you need speed. Here are some shortcuts: - The day of the week repeats every 400 years (since 400 years have 0 odd days). So you can reduce the year modulo 400. - For a given date, you can use the formula: (year_code + month_code + day) % 7. Year codes: for 1900-1999, year_code = (last two digits + last two digits // 4) % 7; for 2000-2099, add 6. Month codes: Jan=6, Feb=2, Mar=2, Apr=5, May=0, Jun=3, Jul=5, Aug=1, Sep=4, Oct=6, Nov=2, Dec=4 (for non-leap years; for leap years, Jan=5, Feb=1). - Alternatively, use the concept of 'reference date'. For example, if you know that January 1, 2024 is Monday, you can compute any date in 2024 by counting days. - Practice with common interview questions: 'What day was January 26, 1950?' (Republic Day of India) or 'What day is December 25, 2025?'

calendar_shortcut.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def day_of_week_shortcut(day, month, year):
    # Using year codes and month codes
    # For years 2000-2099: year_code = (yy + yy//4) % 7 + 6
    yy = year % 100
    year_code = (yy + yy // 4) % 7
    if 2000 <= year <= 2099:
        year_code = (year_code + 6) % 7
    # Month codes for non-leap year
    month_codes = [0, 6, 2, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4]
    if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
        month_codes[1] = 5
        month_codes[2] = 1
    total = (year_code + month_codes[month] + day) % 7
    days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
    return days[total]

print(day_of_week_shortcut(26, 1, 1950))  # Thursday
Output
Thursday
🔥Why 400 years?
🎯 Key Takeaway
Use year and month codes for rapid calculation; memorize the codes for common years.

Clock Angle Problems

Clock problems often ask for the angle between the hour and minute hands at a given time. The hour hand moves 0.5 degrees per minute (360° in 12 hours = 0.5° per minute). The minute hand moves 6 degrees per minute (360° in 60 minutes = 6° per minute). At time H hours and M minutes, the angle is |30H - 5.5M| degrees. Take the smaller angle (min(angle, 360-angle)). For example, at 3:15, angle = |303 - 5.515| = |90 - 82.5| = 7.5°. The hands coincide when the angle is 0, which happens when 30H = 5.5M, i.e., M = (60/11)*H. So they coincide approximately every 65 minutes. Common interview questions: 'Find the angle between hands at 4:20' or 'At what time between 5 and 6 will the hands be together?'

clock_angle.pyPYTHON
1
2
3
4
5
6
7
8
def clock_angle(hour, minute):
    # Ensure hour in 12-hour format
    hour = hour % 12
    angle = abs(30 * hour - 5.5 * minute)
    return min(angle, 360 - angle)

print(clock_angle(3, 15))  # 7.5
print(clock_angle(4, 20))  # 10.0
Output
7.5
10.0
💡Quick Check
📊 Production Insight
In digital clocks, ensure you handle 24-hour format by converting to 12-hour.
🎯 Key Takeaway
Remember the formula |30H - 5.5M| and always take the smaller angle.

Clock Coincidence and Opposite Problems

The hands coincide when the angle is 0. Solving 30H = 5.5M gives M = (60/11)*H. For H=1 to 11, the times are approximately 1:05:27, 2:10:55, etc. The hands are opposite (180°) when |30H - 5.5M| = 180. This gives two solutions per hour except for some. For example, between 5 and 6, they are opposite at about 5:27:16. Also, the hands are at right angles (90°) twice per hour (except near 3 and 9). These problems test your ability to solve linear equations with modular arithmetic. In interviews, you may be asked to find the exact time (in seconds) when hands coincide.

coincide_time.pyPYTHON
1
2
3
4
5
6
7
8
9
def coincide_time(hour):
    # Returns the minute (with fraction) when hands coincide after 'hour'
    # For hour between 1 and 11
    minute = (60 * hour) / 11
    return minute

for h in range(1, 12):
    m = coincide_time(h)
    print(f"{h}:{int(m)}:{int((m%1)*60):02d}")
Output
1:5:27
2:10:54
3:16:21
4:21:49
5:27:16
6:32:43
7:38:10
8:43:38
9:49:05
10:54:32
12:0:0
⚠ Common Mistake
🎯 Key Takeaway
Use the formula M = (60/11)*H for coincidence; for opposite, solve |30H - 5.5M| = 180.

Calendar Problems with Code: Zeller's Congruence

Zeller's congruence is a mathematical formula to calculate the day of the week for any date. It works for both Julian and Gregorian calendars. The formula is: h = (q + floor((13*(m+1))/5) + K + floor(K/4) + floor(J/4) - 2J) mod 7, where q is day, m is month (3=March, ..., 14=February), K is year of the century, J is zero-based century. For January and February, treat them as months 13 and 14 of the previous year. The result h: 0=Saturday, 1=Sunday, ..., 6=Friday. This is efficient for programming and avoids manual odd day counting. In interviews, you can implement this in Python or Java to verify your mental calculation.

zellers_congruence.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
def zellers(day, month, year):
    if month < 3:
        month += 12
        year -= 1
    q = day
    m = month
    K = year % 100
    J = year // 100
    h = (q + (13*(m+1))//5 + K + K//4 + J//4 - 2*J) % 7
    days = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
    return days[h]

print(zellers(1, 1, 2024))  # Monday
print(zellers(26, 1, 1950))  # Thursday
Output
Monday
Thursday
🔥Zeller's vs Odd Days
📊 Production Insight
In production, prefer using built-in date libraries; Zeller's is useful for understanding.
🎯 Key Takeaway
Zeller's congruence is a reliable programming solution for day-of-week calculations.

Advanced Clock Problems: Reflection and Gaining/Losing

Some problems involve clocks that gain or lose time. For example, a clock gains 5 minutes per hour. To find the actual time when the clock shows a certain time, you need to calculate the ratio. If the clock gains, it runs faster; the time elapsed on the clock is more than actual time. The formula: actual time = (clock time) * (normal rate / faulty rate). Also, problems about mirror images: the time seen in a mirror is the reflection. For a 12-hour clock, the mirror image time is 11:60 - actual time (if actual time is in hours and minutes). For example, if actual time is 4:30, mirror shows 7:30. These are common in exams.

mirror_time.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
def mirror_time(hour, minute):
    # Convert to minutes past 12:00
    total_minutes = hour * 60 + minute
    mirror_minutes = (12*60 - total_minutes) % (12*60)
    if mirror_minutes == 0:
        return (12, 0)
    h = mirror_minutes // 60
    m = mirror_minutes % 60
    return (h if h != 0 else 12, m)

print(mirror_time(4, 30))  # (7, 30)
print(mirror_time(12, 0))  # (12, 0)
Output
(7, 30)
(12, 0)
💡Mirror Trick
🎯 Key Takeaway
For faulty clocks, use ratios; for mirror images, subtract from 12:00.

Interview Tips and Common Pitfalls

In interviews, you'll be expected to solve these problems quickly and explain your reasoning. Start by stating the formula or approach. For calendar problems, mention odd days and leap year rules. For clock problems, mention relative speed. Common pitfalls: forgetting that the hour hand moves continuously, not accounting for leap years correctly, and using 24-hour format without converting. Also, be careful with AM/PM. Practice with a timer to improve speed. Use code to verify but focus on mental math. For example, if asked 'What is the angle at 6:30?', you can quickly compute: |306 - 5.530| = |180 - 165| = 15°. Always double-check with a simple example.

⚠ Watch Out
🎯 Key Takeaway
Practice mental math and always verify with a known reference.
● Production incidentPOST-MORTEMseverity: high

The Calendar Bug That Crashed a Booking System

Symptom
Customers could not book flights for February 29, 2020, and the system showed an error.
Assumption
The developer assumed leap years occur every 4 years without exception.
Root cause
The code did not account for century years not divisible by 400 (e.g., 1900 is not a leap year, but 2000 is).
Fix
Updated the leap year logic to check divisibility by 400 for century years.
Key lesson
  • Always handle edge cases like leap years and century years.
  • Use well-tested libraries for date calculations.
  • Test with boundary dates (e.g., Feb 28, Feb 29, Mar 1).
  • Document assumptions about date ranges.
  • Add unit tests for leap year logic.
Production debug guideSymptom to Action3 entries
Symptom · 01
Wrong day of week for historical dates
Fix
Check if the calendar system (Gregorian vs Julian) is correctly applied. Verify leap year rules.
Symptom · 02
Clock angle calculation off by a few degrees
Fix
Ensure you're using the correct formula: angle = |30H - 5.5M|. Check if the time is in 12-hour format.
Symptom · 03
Time difference calculation incorrect across DST
Fix
Use UTC for calculations and convert to local time only for display. Account for daylight saving changes.
★ Quick Debug Cheat SheetCommon symptoms and immediate actions for calendar/clock problems.
Wrong day of week
Immediate action
Recalculate odd days modulo 7
Commands
python -c "print((sum_of_odd_days) % 7)"
python -c "import datetime; print(datetime.date(year, month, day).strftime('%A'))"
Fix now
Use Python's datetime to verify, then adjust odd days count.
Clock angle mismatch+
Immediate action
Check formula: angle = |30*H - 5.5*M|
Commands
python -c "H=3; M=15; print(abs(30*H - 5.5*M))"
python -c "print(min(angle, 360-angle))"
Fix now
Ensure H is in 12-hour format and angle is the smaller one.
Leap year miscalculation+
Immediate action
Test with year 1900, 2000, 2020
Commands
python -c "def is_leap(y): return y%4==0 and (y%100!=0 or y%400==0)"
python -c "print(is_leap(1900), is_leap(2000))"
Fix now
Implement correct leap year logic as above.
MethodBest ForComplexityAccuracy
Odd DaysMental mathLowHigh
Year/Month CodesQuick calculationMediumHigh
Zeller's CongruenceProgrammingMediumHigh
Brute Force (Count Days)Small date rangesHighHigh
⚙ Quick Reference
6 commands from this guide
FileCommand / CodePurpose
odd_days.pydef day_of_week(day, month, year):Understanding Odd Days and Leap Years
calendar_shortcut.pydef day_of_week_shortcut(day, month, year):Calendar Formulas and Shortcuts
clock_angle.pydef clock_angle(hour, minute):Clock Angle Problems
coincide_time.pydef coincide_time(hour):Clock Coincidence and Opposite Problems
zellers_congruence.pydef zellers(day, month, year):Calendar Problems with Code
mirror_time.pydef mirror_time(hour, minute):Advanced Clock Problems

Key takeaways

1
Master odd days and leap year rules for calendar problems.
2
Remember the clock angle formula |30H - 5.5M| and always take the smaller angle.
3
Use Zeller's congruence for programming solutions.
4
Practice mental math with common dates and times.
5
Be careful with mirror images and faulty clocks.

Common mistakes to avoid

4 patterns
×

Assuming the hour hand stays at the hour mark when calculating angle.

×

Forgetting leap year rules for century years.

×

Using 24-hour format directly in clock angle formula.

×

Not taking the smaller angle when calculating clock angle.

INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
What day of the week was August 15, 1947?
Q02JUNIOR
Find the angle between the hour and minute hands at 5:40.
Q03SENIOR
At what time between 4 and 5 will the hands of a clock be opposite?
Q04JUNIOR
How many times in a day do the hour and minute hands coincide?
Q05SENIOR
A clock gains 5 minutes per hour. If it shows 12:00 at noon, what will i...
Q01 of 05SENIOR

What day of the week was August 15, 1947?

ANSWER
Using odd days: 1946 years have 1946365 + leap years. Leap years from 1 to 1946: 1946//4 - 1946//100 + 1946//400 = 486 - 19 + 4 = 471. Total days = 1946365 + 471 = 710, 290 + 471 = 710,761? Actually, better: 1946 mod 400 = 346? Use shortcut: 1947 is not leap. Year code for 1947: (47+11)%7=58%7=2. Month code for Aug = 1. Day=15. Total=2+1+15=18%7=4 => Friday. So August 15, 1947 was Friday.
FAQ · 5 QUESTIONS

Frequently Asked Questions

01
How do I calculate the day of the week for any date quickly?
02
What is the formula for the angle between clock hands?
03
How do I find when the hands of a clock coincide?
04
What is a leap year?
05
How do I solve mirror image clock problems?
N
Naren Founder & Principal Engineer

20+ years shipping production code across the stack, with years spent interviewing engineers. Lessons pulled from things that broke in production.

Follow
Verified
production tested
July 13, 2026
last updated
2,165
articles · all by Naren
🔥

That's Aptitude. Mark it forged?

4 min read · try the examples if you haven't

Previous
Data Sufficiency Problems
16 / 16 · Aptitude
Next
Top DevOps Interview Questions