Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Home
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets

Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
Jobs
Learning
Career Tools
Talentd Logo
Talentd#1 Freshers Platform
DSA Corner
DashboardQuestionsTopicsCompaniesSheets
Back to Problems

680. Valid Palindrome II

Easy41.9% Acceptance
Two PointersStringGreedy
Asked by:
F
Facebook
ProblemSolutions (12)VideosCompanies (7)Notes

Problem Statement

Given a string s, return true if the s can be palindrome after deleting at most one character from it.

Example 1:

Input: s = "aba"
Output: true

Example 2:

Input: s = "abca"
Output: true
Explanation: You could delete the character 'c'.

Example 3:

Input: s = "abc"
Output: false

Constraints:

  • 1 <= s.length <= 105
  • s consists of lowercase English letters.
Talentd Logo
Talentd

Your trusted platform to ace any job interviews, craft the perfect resumes, and land your dream jobs.

P
Featured on
Product Hunt
▲455
All services are online

Products

  • Resume Review
  • Company Prep Pack
  • DSA Corner
  • Jobs
  • Internships
  • Fresher Jobs
  • Roadmaps
  • Tax Calculator

Resources

  • Articles
  • DRDO Internships

Support

  • Contact Us

DSA & Interview Prep

  • DSA Questions
  • DSA Sheets
  • Company Questions
  • Topics

Company

  • Companies Hiring
  • About
  • Contact
  • Advertisement

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Delivery Policy

Popular Skills

Browse All Skills →

Popular Tags

Browse All Tags →

© 2025 Talentd.in - All rights reserved

Privacy PolicyTerms & Conditions
A
Amazon
M
Microsoft
A
Apple
B
Bloomberg
+2

Approach

In #680 Valid Palindrome II, the goal is to determine whether a string can become a palindrome after deleting at most one character. A palindrome reads the same forward and backward, which naturally suggests a two-pointer technique.

Start with two pointers: one at the beginning and one at the end of the string. Move them inward while characters match. If a mismatch occurs, you are allowed to remove one character. At this point, check whether skipping either the left character or the right character forms a valid palindrome. This greedy decision works because only one deletion is permitted.

To verify the remaining substring, you can run a simple palindrome check between the updated indices. This keeps the implementation clean and efficient.

The overall time complexity remains O(n) since each character is visited at most a constant number of times, while the space complexity is O(1) because the algorithm uses only a few pointers.

Complexity

ApproachTime ComplexitySpace Complexity
Two Pointers with One Allowed DeletionO(n)O(1)
Brute Force (try deleting each character)O(n^2)O(1)

Video Solution Available

NeetCode

View all video solutions

Solutions (12)

Two Pointer Technique

This approach uses the two-pointer technique to check if the string is a palindrome after removing at most one character. Start with two pointers at the beginning and end of the string. Move inward while the characters at these pointers are equal. If a mismatch occurs, there are two possibilities: either remove the character at the left pointer or the right pointer. If either results in a palindrome, then the string can be considered a valid palindrome after one deletion.

Time Complexity: O(n), where n is the length of the string.
Space Complexity: O(1) as we use a constant amount of extra space.

CC++JavaPythonC#JavaScript
1#include <stdbool.h>
2#include <string.h>
3
4bool isPalindromeRange(char * s, int i, int j) {
5    

Explanation

The solution uses helper function isPalindromeRange to check if a sub-range of the string is a palindrome. The main function, validPalindrome, attempts to verify if the string becomes a palindrome after removing one mismatched character, if any.

Recursive Two Pointers Method

This approach uses recursion to accomplish the same task. When encountering the first differing pair of characters, we make two recursive calls: one ignoring the left character and one ignoring the right character. If either recursive call results in a valid palindrome, the whole string can be considered a valid palindrome after a single character deletion.

Time Complexity: O(n)
Space Complexity: O(1) by avoiding deep recursive stacks through tail optimization.

CC++JavaPythonC#JavaScript
1


Video Solutions

Watch expert explanations and walkthroughs

Valid Palindrome II - Leetcode 680 - Python

NeetCode
7:4658,944 views

Asked By Companies

7 companies
F
Facebook
A
Amazon
M
Microsoft
A
Apple
B
Bloomberg
O
Oracle
W
Walmart Global Tech

Prepare for Interviews

Practice problems asked by these companies to ace your technical interviews.

Explore More Problems

Notes

Personal Notes

Jot down your thoughts, approach, and key learnings

0 characters

Similar Problems

Longest Palindromic SubstringMedium
Find the Index of the First Occurrence in a StringEasy
Valid PalindromeEasy
Reverse Words in a StringMedium
More similar problems

Related Topics

Two PointersStringGreedy

Problem Stats

Acceptance Rate41.9%
DifficultyEasy
Companies7

Practice on LeetCode

Solve with full IDE support and test cases

Solve Now

Frequently Asked Questions

Is Valid Palindrome II asked in FAANG interviews?

Yes, variations of palindrome checking problems are commonly asked in FAANG and other top tech company interviews. They test understanding of two-pointer strategies and edge-case handling.

What is the optimal approach for Valid Palindrome II?

The optimal approach uses the two-pointer technique. Traverse from both ends of the string and allow one mismatch where you skip either the left or right character and verify the remaining substring. This keeps the time complexity linear.

What data structure is best for solving Valid Palindrome II?

No complex data structure is required. The problem can be solved efficiently using simple string indexing and two pointers, making it both memory-efficient and easy to implement.

Why does the two-pointer method work well for palindrome problems?

The two-pointer approach works because palindromes are symmetric around their center. By comparing characters from both ends simultaneously, you can quickly detect mismatches and handle constraints like allowing one deletion.

while
(
i
<
j
)
{
6
if
(
s
[
i
]
!=
s
[
j
]
)
return
false
;
7
i
++
;
8
j
--
;
9
}
10
return
true
;
11
}
12
13
bool
validPalindrome
(
char
*
s
)
{
14
int
left
=
0
;
15
int
right
=
strlen
(
s
)
-
1
;
16
while
(
left
<
right
)
{
17
if
(
s
[
left
]
!=
s
[
right
]
)
{
18
return
isPalindromeRange
(
s
,
left
+
1
,
right
)
||
isPalindromeRange
(
s
,
left
,
right
-
1
)
;
19
}
20
left
++
;
21
right
--
;
22
}
23
return
true
;
24
}
#
include
<stdbool.h>
2
#
include
<string.h>
3
4
bool
isPalindromeRange
(
char
*
s
,
int
i
,
int
j
)
{
5
while
(
i
<
j
)
{
6
if
(
s
[
i
]
!=
s
[
j
]
)
return
false
;
7
i
++
;
8
j
--
;
9
}
10
return
true
;
11
}
12
13
bool
validPalindromeHelper
(
char
*
s
,
int
i
,
int
j
,
bool deleted
)
{
14
while
(
i
<
j
)
{
15
if
(
s
[
i
]
!=
s
[
j
]
)
{
16
if
(
deleted
)
return
false
;
17
return
validPalindromeHelper
(
s
,
i
+
1
,
j
,
true
)
||
validPalindromeHelper
(
s
,
i
,
j
-
1
,
true
)
;
18
}
19
i
++
;
20
j
--
;
21
}
22
return
true
;
23
}
24
25
bool
validPalindrome
(
char
*
s
)
{
26
return
validPalindromeHelper
(
s
,
0
,
strlen
(
s
)
-
1
,
false
)
;
27
}

Explanation

The C solution applies a helper function that manages recursive calls whenever a mismatched pair of characters is found, implementing an efficient recursive resolution.