You are a senior software architect with expertise in multiple programming paradigms and languages. Generate production-quality implementation(s) for the following functionality, adhering to language-specific best practices, design patterns, and performance considerations.
FUNCTIONALITY SPECIFICATION:
- Description: [Functionality Description]
- Target Languages: [Target Programming Languages]
- Complexity Level: [Basic/Intermediate/Advanced]
- Implementation Style: [Procedural/Object-Oriented/Functional/Hybrid]
INPUT/OUTPUT SPECIFICATIONS:
- Input Parameters: [List input parameters with data types, e.g., (int n, string name)]
- Output: [Specify output type and format, e.g., JSON object, integer, or boolean]
- Error Handling: [Specify expected exceptions and handling approach]
TECHNICAL CONSTRAINTS:
- Time Complexity: [Required algorithmic efficiency, e.g., O(n), O(log n)]
- Space Complexity: [Maximum memory usage, e.g., O(1), O(n)]
- External Dependencies: [Allowed/disallowed libraries or frameworks]
- Minimum Language Version: [e.g., Python 3.9+, Java 11+]
- Platform Compatibility: [e.g., Cross-platform, Linux-only]
- Threading Requirements: [Single-threaded/Multi-threaded/Async]
QUALITY REQUIREMENTS:
- Code Style: [Follow specific style guide, e.g., PEP 8, Google Java Style]
- Documentation: [Level of detail required for comments/documentation]
- Testing Approach: [Unit tests, property-based tests, test coverage expectations]
- Edge Case Handling: [Specific edge cases that must be handled]
EXAMPLE SCENARIOS:
1. Example Input: [Sample input values]
Expected Output: [Expected result for sample input]
2. Example Input: [Another sample input, preferably edge case]
Expected Output: [Expected result for edge case]
3. [Additional examples as needed]
IMPLEMENTATION REQUIREMENTS:
1. Provide complete, executable code (not pseudocode)
2. Include comprehensive error handling
3. Add inline comments explaining complex logic or non-obvious decisions
4. Implement proper input validation
5. Use appropriate data structures and algorithms
6. Follow language idioms and conventions
7. Structure code for readability and maintainability
8. Include example usage showing how to call the function/method
FOR EACH LANGUAGE IMPLEMENTATION, PROVIDE:
1. Code block with language-specific syntax highlighting
2. Brief explanation of language-specific implementation choices
3. Any language-specific optimizations applied
4. Setup/installation instructions if applicable
5. Basic testing approach for the implementation
[Optional: Include additional sections for specific requirements such as security considerations, internationalization support, accessibility features, etc., as relevant to the functionality]
Example Response
You are a senior software architect with expertise in multiple programming paradigms and languages. Generate production-quality implementation(s) for the following functionality, adhering to language-specific best practices, design patterns, and performance considerations.
FUNCTIONALITY SPECIFICATION:
- Description: Create a function that finds the longest palindromic substring in a given string
- Target Languages: Python, JavaScript, Java
- Complexity Level: Intermediate
- Implementation Style: Procedural with functional elements
INPUT/OUTPUT SPECIFICATIONS:
- Input Parameters: (string s) - A string containing alphanumeric characters and spaces
- Output: String representing the longest palindromic substring found
- Error Handling: Return empty string for null/empty inputs, handle non-string inputs appropriately
TECHNICAL CONSTRAINTS:
- Time Complexity: O(n²) or better
- Space Complexity: O(1) preferred, O(n) acceptable
- External Dependencies: No external libraries allowed, only standard language features
- Minimum Language Version: Python 3.7+, JavaScript ES6+, Java 11+
- Platform Compatibility: Cross-platform
- Threading Requirements: Single-threaded
QUALITY REQUIREMENTS:
- Code Style: Follow language-specific conventions (PEP 8 for Python, Google style for Java/JS)
- Documentation: Include docstrings/comments explaining approach and complexity
- Testing Approach: Include at least 3 test cases covering normal cases and edge cases
- Edge Case Handling: Empty strings, single character strings, strings with no palindromes
EXAMPLE SCENARIOS:
1. Example Input: "babad"
Expected Output: "bab" or "aba" (both are valid)
2. Example Input: "cbbd"
Expected Output: "bb"
3. Example Input: "a"
Expected Output: "a"
4. Example Input: "ac"
Expected Output: "a" or "c" (both are valid)
5. Example Input: ""
Expected Output: ""
IMPLEMENTATION REQUIREMENTS:
1. Provide complete, executable code (not pseudocode)
2. Include comprehensive error handling
3. Add inline comments explaining complex logic or non-obvious decisions
4. Implement proper input validation
5. Use appropriate data structures and algorithms
6. Follow language idioms and conventions
7. Structure code for readability and maintainability
8. Include example usage showing how to call the function/method
FOR EACH LANGUAGE IMPLEMENTATION, PROVIDE:
1. Code block with language-specific syntax highlighting
2. Brief explanation of language-specific implementation choices
3. Any language-specific optimizations applied
4. Setup/installation instructions if applicable
5. Basic testing approach for the implementation