Solve checksum and dependency debugging tasks
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Take-home Project
Quick Answer: This question evaluates skills in string processing, modular arithmetic-based checksum computation and mapping, plus debugging of feature enablement logic that involves configuration parsing, dependency resolution, and cycle detection.
Part 1: Build a Validation String from Checksums
Constraints
- 0 <= len(s) <= 10^5
- 1 <= len(validation_chars) <= 10^5
- 1 <= k <= 10^5
- len(s) is a multiple of k
- s contains only lowercase English letters
Examples
Input: ('abcd', 'wxyz', 2)
Expected Output: 'xx'
Explanation: 'ab' -> 0+1=1 -> index 1 -> 'x'; 'cd' -> 2+3=5 -> 5%4=1 -> 'x'.
Input: ('zzzz', 'abc', 2)
Expected Output: 'cc'
Explanation: Each block 'zz' has checksum 25+25=50. Since 50%3=2, each block contributes 'c'.
Input: ('leetcode', 'abcde', 4)
Expected Output: 'dd'
Explanation: 'leet' sums to 38 and 'code' sums to 23. Both give index 3 when taken modulo 5.
Input: ('', 'abc', 2)
Expected Output: ''
Explanation: An empty input string has no blocks, so the result is also empty.
Hints
- Process the string one block of length k at a time.
- Use ord(ch) - ord('a') to convert a lowercase letter into its alphabet index.
Part 2: Determine Which Requested Features Can Be Enabled
Constraints
- 0 <= number of features <= 10^4
- 0 <= total number of dependency edges <= 5 * 10^4
- 0 <= user_os_version <= 10^9
- Feature names are unique strings
- requested contains unique feature names
- pre_enabled contains unique feature names
Examples
Input: ({'core': {'countries': ['US', 'CA'], 'min_version': 1, 'dependencies': []}, 'chat': {'countries': ['US'], 'min_version': 2, 'dependencies': ['core']}, 'video': {'countries': ['US'], 'min_version': 3, 'dependencies': ['chat']}}, 'US', 3, [], ['chat', 'video'])
Expected Output: ['chat', 'video']
Explanation: 'core' can be enabled automatically, so both requested features are valid.
Input: ({'core': {'countries': ['US', 'CA'], 'min_version': 1, 'dependencies': []}, 'chat': {'countries': ['US'], 'min_version': 2, 'dependencies': ['core']}, 'pay': {'countries': ['GB'], 'min_version': 4, 'dependencies': []}}, 'US', 3, [], ['chat', 'pay'])
Expected Output: ['chat']
Explanation: 'chat' is valid. 'pay' is invalid because the user is not in an allowed country and also does not meet the minimum OS version.
Input: ({'A': {'countries': ['US'], 'min_version': 1, 'dependencies': ['B']}, 'B': {'countries': ['US'], 'min_version': 1, 'dependencies': ['A']}, 'C': {'countries': ['US'], 'min_version': 1, 'dependencies': []}}, 'US', 1, [], ['A', 'C'])
Expected Output: ['C']
Explanation: 'A' and 'B' form a cycle, so 'A' cannot be enabled. 'C' has no dependencies and is valid.
Input: ({'auth': {'countries': ['CA'], 'min_version': 10, 'dependencies': []}, 'dashboard': {'countries': ['US'], 'min_version': 1, 'dependencies': ['auth']}}, 'US', 1, ['auth'], ['dashboard'])
Expected Output: ['dashboard']
Explanation: 'auth' is already pre-enabled, so it satisfies the dependency immediately.
Input: ({'base': {'countries': ['US'], 'min_version': 1, 'dependencies': []}}, 'US', 5, [], [])
Expected Output: []
Explanation: With no requested features, the result is empty.
Hints
- Model feature dependencies as a directed graph.
- Use DFS with memoization and a visiting state to detect cycles and avoid recomputing the same feature repeatedly.