FastPrepLongest Palindromic Subsequence
Problems/Longest Palindromic Subsequence

Longest Palindromic Subsequence

Goldman Sachs logoGoldman Sachs● MediumNEW GRADINTERNOA
QuestionFunctionExamples

Problem statement

Source note: The reported task identifies this algorithmic exercise. The executable interface, bounds, deterministic tie rules, and examples are the documented practice contract.

Special thanks: 🌷 A special thank you to a lovely, amazing fren for sharing a similar interview question, with reported date of October 17, 2026! (∩˃o˂∩)♡ 🩷

Given a string s, return the length of its longest subsequence that reads the same from left to right and right to left.

A subsequence keeps the relative order of selected characters but does not need to use contiguous positions.

Function

longestPalindromeSubseq(s: String) → int

Examples

Example 1

s = "bbbab"return = 4

One longest palindromic subsequence is bbbb.

Example 2

s = "cbbd"return = 2

More Goldman Sachs problems

  • Palindrome CounterOA · Seen Oct 2026
  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int longestPalindromeSubseq(String s) {
      // write your code here
    }
}
Checking account…