DEV Community

Cover image for Daily DSA and System Design Journal - 14
I.K
I.K

Posted on

Daily DSA and System Design Journal - 14

🧠 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
Enter fullscreen mode Exit fullscreen mode

βš™οΈ 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.

Top comments (0)