Minimum Insertions to Make a Palindrome
Updated
Problem statement
Given a string s, return the minimum number of characters that must be inserted to make it a palindrome.
You may insert a character at any position, including either end. You may not delete, replace, or reorder the original characters. A palindrome reads the same from left to right and from right to left. The empty string is already a palindrome.
For this exercise, assume that the string contains only lowercase English letters.
Function
minInsertions(s: String) → intExamples
Example 1
s = "abc"return = 2Insert b and a after the final character to get abcba. Two insertions are necessary because the three original characters are all different.
Example 2
s = "racecar"return = 0The input already reads the same in both directions.
Constraints
- For this exercise, assume
0 <= s.length <= 1000. - Every character is a lowercase English letter.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai · OA
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA
- Longest Subsequence That Is a SubstringWells Fargo · OAWells Fargo interview questions