PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in string manipulation and algorithmic problem-solving, focusing on palindrome detection and substring handling within the Coding & Algorithms domain.

  • easy
  • TikTok
  • Coding & Algorithms
  • Software Engineer

Find the longest palindromic substring

Company: TikTok

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem Given a string `s`, return the **longest contiguous substring** of `s` that is a **palindrome** (reads the same forward and backward). ## Input - `s`: a non-empty string of length `n` ## Output - A substring of `s` that is the longest palindrome. If multiple answers exist, return any one. ## Constraints - `1 ≤ n ≤ 2000` - `s` contains ASCII letters/digits (you may assume no spaces). ## Examples - Input: `"babad"` → Output: `"bab"` (or `"aba"`) - Input: `"cbbd"` → Output: `"bb"`

Quick Answer: This question evaluates proficiency in string manipulation and algorithmic problem-solving, focusing on palindrome detection and substring handling within the Coding & Algorithms domain.

Given a string `s`, return the longest contiguous substring of `s` that is a palindrome. A palindrome reads the same forward and backward. If there are multiple longest palindromic substrings, return any one of them.

Constraints

  • 1 <= len(s) <= 2000
  • s contains only ASCII letters and digits
  • The substring must be contiguous

Examples

Input: "babad"

Expected Output: "bab"

Explanation: Both "bab" and "aba" are valid longest palindromes of length 3. This solution keeps the first one it finds, which is "bab".

Input: "cbbd"

Expected Output: "bb"

Explanation: The longest palindromic substring is the even-length palindrome "bb".

Input: "a"

Expected Output: "a"

Explanation: A single character is always a palindrome.

Input: "ac"

Expected Output: "a"

Explanation: There are no palindromes longer than length 1. This solution returns the first one, "a".

Input: "forgeeksskeegfor"

Expected Output: "geeksskeeg"

Explanation: "geeksskeeg" is the longest palindromic substring.

Input: "aaaa"

Expected Output: "aaaa"

Explanation: The entire string is a palindrome.

Hints

  1. A palindrome can be expanded outward from its center. Try considering both odd-length and even-length centers.
  2. For each index, check the longest palindrome centered at that index and between that index and the next one.
Last updated: May 9, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Parse a nested list from a string - TikTok (medium)
  • Implement stacks, streaming median, and upward path sum - TikTok (easy)
  • Implement stack variants and path-sum check - TikTok (medium)
  • Solve common string/DP/stack problems - TikTok (medium)
  • Maximize sum with no adjacent elements - TikTok (medium)