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).