Explain the sliding window technique and apply it to solve:
(
-
Given an array of positive integers and a target S, return the minimal length of a contiguous subarray with sum ≥ S (or 0 if none);
(
-
Given a string and an integer K, return the length of the longest substring containing at most K distinct characters; Analyze time and space complexity and when to use fixed vs. dynamic windows.