FastPrepMinimum Insertion Steps to Make a String Palindrome
Problems/Minimum Insertion Steps to Make a String Palindrome

Minimum Insertion Steps to Make a String Palindrome

Infosys logoInfosys● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: In the technical interview, the candidate was asked on paper for the fewest operations that turn a string into a palindrome. They named it as LeetCode 1312 and explained a brute-force idea.

The operation is not spelled out beyond that name, so this version uses the usual rule of that problem: each step inserts one character anywhere. It was a paper question; here the code is judged.

The judged task matches the report at about 90%.

You are given a string s. In one step you may insert any single character at any position of the string (at the start, at the end, or between two characters).

Return the smallest number of steps needed to make s a palindrome. A palindrome reads the same forwards and backwards.

Function

minInsertions(s: String) → int

Examples

Example 1

s = "abca"return = 1

Insert b between c and the last a to get abcba, which is a palindrome. abca itself is not a palindrome, so at least one step is needed.

Example 2

s = "race"return = 3

Insert e, c, and a at the front to get ecarace. No two letters of race are equal, so every letter except one must get a matching partner, and each partner costs one step.

Example 3

s = "noon"return = 0

noon is already a palindrome, so no steps are needed.

Constraints

  • 1 <= s.length <= 500
  • s contains only lowercase English letters

More Infosys Onsite Interview questions

  • Minimum Coins for a TargetONSITE INTERVIEW · Seen Nov 2026
  • Delete Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
  • Find Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
  • Maximize the Even-Odd Index Product GapONSITE INTERVIEW · Seen Oct 2026
  • Minimum Nonadjacent Flips for an Alternating Binary StringONSITE INTERVIEW · Seen Oct 2026
  • Tenth-Highest Distinct SalaryONSITE INTERVIEW · Seen Oct 2026
  • Assign Cookies With Matching ParityONSITE INTERVIEW · Seen Sep 2026
  • Count Equal Code Pairs Within Distance KONSITE INTERVIEW · Seen Sep 2026
  • Daily Successful Transactions Per DepartmentONSITE INTERVIEW · Seen Sep 2026
  • Detect Substring In Any RotationONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
  • Concatenated WordsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Interleaving StringsCARS24 · ONSITE INTERVIEW
  • Minimum Stickers to Form a Target StringByteDance · ONSITE INTERVIEWByteDance interview questions
  • Longest Valid ParenthesesMathWorks · ONSITE INTERVIEWMathWorks interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Word Break II: All SentencesMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Longest Valid ParenthesesMaven Clinic · ONSITE INTERVIEWMaven Clinic interview questions
  • Word Break IIGoogle · ONSITE INTERVIEWGoogle interview questions
  • Maximum Bouquet ValueOracle · ONSITE INTERVIEWOracle interview questions
All Infosys interview questionsSee Infosys hiring insights
Saved
class Solution {
    public int minInsertions(String s) {
        // Write your code here.
    }
}
Checking account…