This question evaluates string-processing skills, algorithmic reasoning, and attention to edge cases by asking for a palindrome detector and a parentheses-sequence validator.
You have 20–25 minutes per problem. Implement the following two functions and be prepared to explain your approach and time/space complexity.
Write a function that determines whether a given string is a palindrome.
Function signature (example):
bool is_palindrome(s: str)
Input:
s
: a string (may be empty)
Output:
true
if
s
is a palindrome, otherwise
false
Examples:
"abba" -> true
"abc" -> false
"" -> true
Write a function that checks whether a string containing only parentheses characters is valid.
A string is valid if:
Assume the allowed bracket types are: (), [], {}.
Function signature (example):
bool is_valid_parentheses(s: str)
Input:
s
: a string consisting only of characters in
()[]{}
(may be empty)
Output:
true
if
s
is valid, otherwise
false
Examples:
"()" -> true
"([]){}" -> true
"(]" -> false
"([)]" -> false
"" -> true
For each function, include a docstring with: