Introduction
Week 11 mainly focuses on:
- String manipulation
- Date handling in Python
- Working with built-in modules
- Writing clean and efficient logic
These concepts are important not only for exams but also for real-world programming.
✅ Q1. Character Reduction Game
❓ Question
You are given two strings. Remove all common characters (one from each string). Repeat the process until no common characters remain.
👉 Finally, print the total number of remaining characters.
💻 Python Code
s2 = input().strip()
from collections import Counter
c1 = Counter(s1)
c2 = Counter(s2)
for ch in c1:
if ch in c2:
common = min(c1[ch], c2[ch])
c1[ch] -= common
c2[ch] -= common
print(sum(c1.values()) + sum(c2.values()))
🧠 Explanation
- Count characters in both strings
- Remove common characters using minimum frequency
- Add remaining characters
👉 This ensures all test cases pass correctly.
✅ Q2. Academic Date Gap Calculator
❓ Question
You are given two dates in YYYY-MM-DD format.
👉 Find the absolute number of days between them.
- Order does not matter
- Leap years should be handled
- Same date → output 0
💻 Python Code
d1 = input().strip()
d2 = input().strip()
date1 = datetime.strptime(d1, “%Y-%m-%d”)
date2 = datetime.strptime(d2, “%Y-%m-%d”)
print(abs((date2 – date1).days))
🧠 Explanation
- Convert string → date using
datetime - Subtract dates → gives difference
- Use
abs()to ensure positive result
👉 Python automatically handles leap years.
✅ Q3. Monthly Calendar Generator
❓ Question
You are given a year and a month (1–12).
👉 Print the calendar in standard format:
- Week starts from Monday
- Ends on Sunday
💻 Python Code
year = int(input().strip())
month = int(input().strip())
cal = calendar.TextCalendar(firstweekday=0)
print(cal.formatmonth(year, month))
🧠 Explanation
- Use Python’s built-in
calendarmodule formatmonth()prints full calendarfirstweekday=0ensures Monday start
👉 Output matches real calendar format.
Common Mistakes to Avoid
Many students lose marks due to small mistakes:
- ❌ Wrong input format
- ❌ Indentation errors in Python
- ❌ Not using built-in modules properly
- ❌ Overcomplicating simple logic
👉 Keep your code clean and simple.
Tips to Score Better
- Practice similar problems
- Understand logic instead of copying
- Test your code with different inputs
- Use Python built-in modules when needed
