Solve sliding-window and disjoint-string-pairs tasks
Company: Netflix
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
## Task A (Sliding Window)
Given a string `s`, find the length of the longest contiguous substring that contains **no repeated characters**.
- **Input:** a string `s`
- **Output:** an integer (maximum length)
- **Constraints (assume):** `1 <= len(s) <= 2e5`; ASCII characters.
## Task B (Disjoint-character string pairs)
Given a list of strings `words`, count the number of **unique unordered pairs** `(i, j)` with `i < j` such that `words[i]` and `words[j]` share **no common characters**.
- Two strings “share no common characters” if there is no character `c` that appears in both strings.
- Count each pair once (order doesn’t matter).
### Example
Input: `["apple", "banana", "peach", "kiwi"]`
Valid unique pairs include:
- ("apple", "kiwi")
- ("banana", "kiwi")
- ("peach", "kiwi")
### Requirements
Design an algorithm with time complexity **O(n log n)** (or better) where `n = len(words)`.
- **Input:** list of strings `words`
- **Output:** integer count of valid pairs
- **Constraints (assume):** `1 <= n <= 2e5`; each word length up to `1e3`; characters are lowercase `a`–`z` (state any additional assumptions you need).
Quick Answer: This question evaluates proficiency in string-processing algorithms, sliding-window techniques, efficient set or bitmask representations, and combinatorial pair counting under strict time and space constraints.
Part 1: Longest Substring Without Repeating Characters
Given a string `s`, return the length of the longest contiguous substring that contains no repeated characters.
A substring must be contiguous. If the input string is empty, return `0`.
Constraints
- 0 <= len(s) <= 2 * 10^5
- Characters are ASCII
- Your algorithm should run in O(n) time
Examples
Input: "abcabcbb"
Expected Output: 3
Explanation: The longest valid substring is "abc", which has length 3.
Input: "bbbbb"
Expected Output: 1
Explanation: Every substring with unique characters can contain only one 'b'.
Input: ""
Expected Output: 0
Explanation: An empty string has no substrings, so the answer is 0.
Input: "dvdf"
Expected Output: 3
Explanation: The best substring is "vdf", which has length 3.