🧠 Day 12 — Smallest Missing Integer & Schedule-Driven Jobs ⚙️
🧩 DSA Problems [1 hr]
Problem: 2598. Smallest Missing Non-negative Integer After Operations
💡 Approach: Greedy
Intuition
Each number in the array can be shifted by multiples of value.
That means all numbers that share the same remainder when divided by value belong to the same transformable group.
Example:
If value = 3, then numbers 0, 3, 6, 9 can all become one another through these operations.
We want to maximize the MEX (minimum excluded non-negative integer).
To do this, we iterate from 0 upward and check if there’s still a number left in the corresponding remainder group (mex % value).
If yes → use one and move forward.
If no → we found our MEX.
💻 Code
class Solution:
def findSmallestInteger(self, nums: List[int], value: int) -> int:
mp = Counter(x % value for x in nums)
mex = 0
while mp[mex % value] > 0:
mp[mex % value] -= 1
mex += 1
return mex
📊 Complexity
| Metric | Complexity |
|---|---|
| ⏱ Time | O(n) |
| 💾 Space | O(value) |
🧩 Key Learnings
- Grouping by modular equivalence can simplify complex transformation logic.
- Greedy strategies work beautifully when you can define a clear incremental choice.
- “Remainders as buckets” is a powerful way to partition search spaces efficiently.
🏗 System Design — Roadmap.sh [1 hr]
⏰ Schedule-Driven Background Jobs
Not every task needs an event or user trigger — some just need to run on time.
That’s where schedule-driven jobs come in: systems that operate on timers, intervals, or cron schedules.
💡 What It Is
A schedule-driven job runs automatically based on time-based triggers such as:
- Every minute/hour/day (
cron,Celery Beat,Airflow DAGs, etc.) - At specific times (
00:00 UTCdaily backup) - After delays (
run job after 5 minutes)
🧱 Common Examples
| Type | Description |
|---|---|
| 🧾 Batch Processing | Aggregate logs, update indexes, or recompute recommendations daily. |
| 📊 Reports & Analytics | Generate daily KPIs or email summaries every morning. |
| 🧹 Maintenance Tasks | Cleanup old data, archive inactive sessions, or delete expired tokens. |
| 🧮 Consistency Checks | Verify data integrity or sync caches periodically. |
⚙️ How It’s Done
- Local Scheduler: OS-based (like cron jobs or Windows Task Scheduler).
- App Scheduler: Framework-level (Celery Beat, Sidekiq Scheduler, or Quartz).
- External Scheduler: Managed cloud services (AWS EventBridge, Azure Logic Apps, Google Cloud Scheduler).
⚠️ Design Considerations
| Concern | Description |
|---|---|
| 🧩 Idempotence | A job might run twice — make sure repeating it doesn’t cause data corruption. |
| 🧍 Single Instance Execution | When your system scales, you must ensure only one instance of the job runs globally. |
| ⏳ Overlapping Jobs | A job may still be running when the next scheduled run starts — use locks or queues to prevent overlap. |
🔗 Great read: What Does Idempotent Mean? (Particular.net)
🧠 Reflection
This day connects two powerful ideas:
- In DSA, you optimized resource use by smartly grouping operations.
- In System Design, you optimized time and execution with predictable schedules.
Both require discipline, rhythm, and state awareness — hallmarks of scalable design, both in code and in life.
✅ Day 12 Summary:
Consistency breeds reliability — in arrays, systems, and habits.
Top comments (0)