Skip to content
Exercise · Strings and Arrays · lesson 5 of 6

Exercise: palindrome

Write a function bool is_palindrome(std::string_view s). It returns true if s is a palindrome, and false otherwise. A palindrome reads the same from left to right and from right to left.

  • is_palindrome("abba") → true
  • is_palindrome("level") → true
  • is_palindrome("abca") → false

Constraints: letter case matters, so "Abba" is not a palindrome; an empty string and a one-character string are palindromes.

Do not add extra #include lines unless the task says so explicitly.

palindrome.cpp — cpp
cpp · 7 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way