Daily DSA and System Design Journal – 14



This content originally appeared on DEV Community and was authored by I.K

🧠 Day 14 — Adjacent Patterns & Domain Resolution

🧩 DSA Problems [1 hr]

Problem: 3350. Adjacent Increasing Subarrays Detection II

💡 Approach: One-time Traversal

🧠 Intuition

We’re looking for adjacent strictly increasing subarrays — essentially, zones where the array keeps climbing before it resets.

We maintain two counters throughout one pass:

  • cnt — current increasing streak
  • precnt — previous streak length

Whenever the sequence stops increasing (nums[i] <= nums[i-1]):

  • the previous count becomes precnt
  • we reset cnt to 1

At every step, there are two possible adjacent subarray pairs to consider:

  1. Current vs. Previous Segment: max potential = min(precnt, cnt)
  2. Single Extended Segment: when both lie within one long increasing run, potential = cnt // 2

By tracking both, we find the maximum adjacent pattern size in a single linear scan.

💻 Code

class Solution:
    def maxIncreasingSubarrays(self, nums: List[int]) -> int:
        n = len(nums)
        cnt, precnt, ans = 1, 0, 0
        for i in range(1, n):
            if nums[i] > nums[i - 1]:
                cnt += 1
            else:
                precnt, cnt = cnt, 1
            ans = max(ans, min(precnt, cnt))
            ans = max(ans, cnt // 2)
        return ans

⚙ Complexity

Measure Complexity
⏱ Time O(n) — single traversal
💾 Space O(1) — constant memory

🔍 Key Learnings

  • One-pass algorithms thrive on state compression — carrying only the info that truly matters.
  • Understanding segment relationships (current vs. previous) simplifies multi-phase problems.
  • Sometimes, the simplest recurrence hides the deepest efficiency.

🌍 SYSTEM DESIGN — Roadmap.sh [1 hr]

🌐 Domain Name System (DNS)

The Domain Name System is the phonebook of the internet — translating human-readable domain names into IP addresses that machines can understand.

When you type www.example.com in your browser, DNS resolves it to something like 93.184.216.34.

🧭 Hierarchical Architecture

  1. Root DNS Servers — top-level, directing queries to TLD (Top-Level Domain) servers.
  2. TLD Servers — responsible for domains like .com, .org, .net, etc.
  3. Authoritative DNS Servers — final source for a given domain’s records.

Your device or local resolver caches results to avoid redundant lookups — governed by TTL (Time To Live).

📑 Common DNS Records

Record Type Purpose
🧭 A Maps domain to IPv4 address
🧭 AAAA Maps domain to IPv6 address
📬 MX Mail Exchange — email routing
🌍 CNAME Canonical Name — points to another domain
🧾 NS Name Server — specifies authoritative DNS servers

🚀 Managed DNS Providers

Modern systems often use managed DNS to add reliability and routing intelligence.
Examples include:

⚖ Routing Policies

Policy Type Description
⚖ Weighted Round Robin Distribute traffic based on server weights — useful for load balancing or A/B testing.
🕓 Latency-Based Routing Direct users to the server with the lowest network latency.
📍 Geolocation Routing Route users to the geographically closest data center.

🧠 Reflection

Both today’s topics — array traversal and DNS resolution — rely on hierarchy and memory.

  • The algorithm builds meaning incrementally — one element at a time.
  • DNS builds resolution hierarchically — one level at a time.

Both turn complex discovery into efficient lookup.

✅ Day 14 Summary:

Whether in data or domains, efficient systems remember just enough and resolve just in time.


This content originally appeared on DEV Community and was authored by I.K