Skip to content

S1Q2 · Is Reverse Combined Palindrome

⚡ Quick Reference

Function: is_reverse_combined_palindrome(s1: str, s2: str) -> bool

Core idea: reverse s1, concatenate with s2, check if the result is a palindrome.

def is_reverse_combined_palindrome(s1: str, s2: str) -> bool:
    combined = s1[::-1] + s2
    return combined == combined[::-1]

Key rules: - Reverse s1 using s1[::-1] - Concatenate: reversed_s1 + s2 - Palindrome check: combined == combined[::-1]


Problem Statement

Problem

Write a function is_reverse_combined_palindrome(s1, s2) that reverses s1, concatenates it with s2, and returns True if the result is a palindrome.

Examples:

Input
s1="mad", s2="am"
Output
False
Input
s1="dam", s2="am"
Output
True

Tracing both examples

Example 1: s1="mad", s2="am"

reversed s1 = "dam"
combined    = "dam" + "am" = "danam"
reversed    = "manad"
"danam" == "manad" → False ✓

Example 2: s1="dam", s2="am"

reversed s1 = "mad"
combined    = "mad" + "am" = "madam"
reversed    = "madam"
"madam" == "madam" → True ✓


Solution approaches

def is_reverse_combined_palindrome(s1: str, s2: str) -> bool:
    combined = s1[::-1] + s2
    return combined == combined[::-1]
def is_reverse_combined_palindrome(s1: str, s2: str) -> bool:
    reversed_s1 = s1[::-1]
    combined    = reversed_s1 + s2
    return combined == combined[::-1]
is_reverse_combined_palindrome = lambda s1, s2: (
    (lambda c: c == c[::-1])(s1[::-1] + s2)
)

Key takeaways

01

s[::-1] reverses a string

Slice with step -1 returns a reversed copy without modifying the original. s1[::-1] reverses s1; applying it again to combined checks the palindrome - same operation, two uses.

02

Order matters - reverse s1 first, then concatenate

The operation is reverse(s1) + s2, not reverse(s1 + s2). Only s1 is reversed; s2 is appended as-is.

03

Return bool - not the string

The template's return type hint says str but the examples return True/False. The function should return a bool - combined == combined[::-1] naturally produces one.