π§ 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
cntto 1
At every step, there are two possible adjacent subarray pairs to consider:
-
Current vs. Previous Segment: max potential =
min(precnt, cnt) -
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
- Root DNS Servers β top-level, directing queries to TLD (Top-Level Domain) servers.
-
TLD Servers β responsible for domains like
.com,.org,.net, etc. - 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)