Implement palindrome check and valid parentheses
Problem Description
YouYou will have 20–25 minutes per problem to implement the following two functions. Be prepared to explain your approach and analyze its time and space complexity for each.
Problem 1: Palindrome Check
Write a function that determines whether a given string is a palindrome.
- A string is a palindrome if it reads the same forward and backward.
- Compare characters exactly as they appear; do not perform case folding or ignore punctuation/whitespace unless you explicitly state and implement such behavior.
Function Signature Example:
bool is_palindrome(s: str)
Input:
s: A string (which may be empty).
Output:
trueifsis a palindrome, otherwisefalse.
Examples:
"abba" -> true"abc" -> false"" -> true
Problem 2: Valid Parentheses Sequence
Write a function that checks whether a string containing only parentheses characters is valid.
A string is valid if:
- Every opening bracket has a corresponding closing bracket of the same type.
- Brackets close in the correct order.
Assume the allowed bracket types are: (), [], {}.
Function Signature Example:
bool is_valid_parentheses(s: str)
Input:
s: A string consisting only of characters from()[]{}(which may be empty).
Output:
trueifsis valid, otherwisefalse.
Examples:
"()" -> true"([]){}" -> true"(]" -> false"([)]" -> false"" -> true
Documentation Requirement
For each function, include a docstring with:
- Description
- Inputs/Outputs
- Callouts (assumptions, edge cases, complexity)
AI interview prep
Core dilemma
Demonstrating fundamental algorithmic proficiency and attention to detail under tight time constraints, balancing efficient implementation with thorough complexity analysis and robust edge case handling for two distinct problems.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement palindrome check and valid parentheses
Problem Description
YouYou will have 20–25 minutes per problem to implement the following two functions. Be prepared to explain your approach and analyze its time and space complexity for each.
Problem 1: Palindrome Check
Write a function that determines whether a given string is a palindrome.
- A string is a palindrome if it reads the same forward and backward.
- Compare characters exactly as they appear; do not perform case folding or ignore punctuation/whitespace unless you explicitly state and implement such behavior.
Function Signature Example:
bool is_palindrome(s: str)
Input:
s: A string (which may be empty).
Output:
trueifsis a palindrome, otherwisefalse.
Examples:
"abba" -> true"abc" -> false"" -> true
Problem 2: Valid Parentheses Sequence
Write a function that checks whether a string containing only parentheses characters is valid.
A string is valid if:
- Every opening bracket has a corresponding closing bracket of the same type.
- Brackets close in the correct order.
Assume the allowed bracket types are: (), [], {}.
Function Signature Example:
bool is_valid_parentheses(s: str)
Input:
s: A string consisting only of characters from()[]{}(which may be empty).
Output:
trueifsis valid, otherwisefalse.
Examples:
"()" -> true"([]){}" -> true"(]" -> false"([)]" -> false"" -> true
Documentation Requirement
For each function, include a docstring with:
- Description
- Inputs/Outputs
- Callouts (assumptions, edge cases, complexity)