AI - Design an Extensible Excel-Like Autofill Engine
Design a simplified Excel-like autofill engine that generates cell values from one or more seed values. As of now there are two strategies, Number strategy and character strategy. A numeric seed increases sequentially, while a character sequence repeats its original pattern.
Autofill Rules
Number Strategy
- The input must contain exactly one valid integer seed.
- The first generated value must equal the supplied seed.
- Every following value increases by
1.
- A numeric seed may contain a leading minus sign, but it must not contain a leading plus sign.
- Leading zeroes are not allowed unless the seed is exactly
"0".
- Negative zero
"-0" is not a valid numeric seed.
Character Sequence Strategy
- Every seed value must contain exactly one English alphabetic character.
- The supplied seed values form the repeating pattern.
- Character case must be preserved.
- After the final character, generation continues from the first character.
Strategy Selection
- The number strategy supports only a list containing exactly one valid numeric seed.
- The character sequence strategy supports only a list in which every value is exactly one English alphabetic character.
- If no strategy supports the entire list of seed values, the engine must return an empty list.
- A strategy must validate all seed values before generating any result.
The design must follow SOLID principles. Each fill type must be implemented as an independent strategy. New strategies such as dates, weekdays, or Fibonacci sequences must be addable without changing the core autofill selection logic or any existing strategy.
Method Signatures
Create the Autofill Engine
AutofillEngine()
- Creates an autofill engine with all built-in strategies.
- The built-in strategies are
NUMBER and CHARACTER_SEQUENCE.
- Both built-in strategies are always available.
Generate Autofill Values
List<String> autofill(List<String> seedValues, int cellCount)
- Returns exactly
cellCount values, including the supplied seed values.
- The engine must use the strategy that supports
seedValues.
- Returns an empty list if none of the built-in strategies supports the seed values.
Constraints
1 ≤ seedValues.size() ≤ 100
1 ≤ cellCount ≤ 100,000
cellCount ≥ seedValues.size()
- A valid numeric seed represents an integer between
-1,000,000,000 and 1,000,000,000.
- A valid character seed contains one English alphabetic character from
a to z or A to Z.
- Every seed value is non-empty.
Examples
Example 1: Sequential Numbers
AutofillEngine() autofill(seedValues = ["12"], cellCount = 5) Output: ["12", "13", "14", "15", "16"]
Explanation: The input contains exactly one valid integer seed, so the number strategy is selected. The first value is "12", and each following value increases by 1 until five values have been generated.
Example 2: Negative Number Seed
AutofillEngine() autofill(seedValues = ["-3"], cellCount = 6) Output: ["-3", "-2", "-1", "0", "1", "2"]
Explanation: "-3" is a valid integer seed, so the number strategy is selected. The strategy increases the value by 1 each time, continuing through zero until six values have been generated.
Example 3: Repeating Character Pattern
AutofillEngine() autofill(seedValues = ["p", "Q", "r"], cellCount = 8) Output: ["p", "Q", "r", "p", "Q", "r", "p", "Q"]
Explanation: Every seed value contains exactly one English alphabetic character, so the character sequence strategy is selected. The pattern ["p", "Q", "r"] repeats from the beginning after "r", and the original character case is preserved.
Example 4: Single Character Pattern
AutofillEngine() autofill(seedValues = ["M"], cellCount = 4) Output: ["M", "M", "M", "M"]
Explanation: The single seed value "M" is a valid English alphabetic character. It forms a pattern of length one, so the character sequence strategy repeats it until four values have been generated.
Example 5: Unsupported Multiple Numeric Seeds
AutofillEngine() autofill(seedValues = ["1", "2"], cellCount = 5) Output: []
Explanation: The number strategy requires exactly one numeric seed, so it does not support two numeric seeds. The character sequence strategy also does not support them because digits are not English alphabetic characters. Therefore, no strategy supports the input, and an empty list is returned.
Example 6: Unsupported Mixed Seeds
AutofillEngine() autofill(seedValues = ["A", "2"], cellCount = 6) Output: []
Explanation: The number strategy does not support the input because it contains more than one seed and "A" is not numeric. The character sequence strategy does not support it because "2" is not an English alphabetic character. Therefore, the engine returns an empty list.
Example 7: Invalid Numeric Format
AutofillEngine() autofill(seedValues = ["01"], cellCount = 4) Output: []
Explanation: "01" is not a valid numeric seed because leading zeroes are not allowed unless the seed is exactly "0". It is also not a valid character seed because it does not contain exactly one English alphabetic character. Therefore, no strategy supports the input, and an empty list is returned.