Strings

Problem shape

Beginner
4
8
15
16
23
42
Core idea

Compare characters from both ends while moving inward.

Step 1 / 5
Problem shape
Current lesson

Palindrome Check Lab

Strings Beginner

Palindrome Check

Welcome to the Palindrome Check algorithm lab. Compare characters from both ends while moving inward. Use it when: Use for strings or arrays that should read the same forward and backward. The time complexity is O(n), and the space complexity is O(1). The pseudocode is: left = 0, right = length - 1 while left < right if s[left] != s[right] return false left++ right-- return true As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(n)

Space

O(1)

Pseudocode

left = 0, right = length - 1
while left < right
  if s[left] != s[right] return false
  left++
  right--
return true
Open deeper structure lesson
1.0x