FastPrepPalindromic Array Transformation
Problems/Palindromic Array Transformation

Palindromic Array Transformation

PayPay logoPayPay● HardNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

SDE I

An array is called palindromic if it remains the same after reversing the order of its elements.

You have an array of strings arr. For each i, arr[i] consists of at least two characters. For each pair of consecutive elements arr[i] and arr[i + 1], you can:

  • Move the rightmost character of arr[i] to the leftmost position in arr[i + 1]. For instance, "abc" and "def" will become "ab" and "cdef". This operation can be applied only once to any pair of consecutive elements.
  • Move the leftmost character of arr[i + 1] to the rightmost position in arr[i]. For instance, "abc" and "def" will become "abcd" and "ef". Again, this operation can be applied only once to any pair of consecutive elements.
  • Do nothing to the pair of consecutive elements.

Is it possible to obtain a palindromic array from arr by performing these operations?

return 1 --> True return 0 --> False

Return 1 if the given array can be turned into a palindromic array, otherwise return 0.

Function

solution(arr: String[]) → int

Examples

Example 1

arr = ["aa", "bab", "cde", "aba", "ab"]return = 1

Apply the second operation to "aa" and "bab". Apply the first operation to "aba" and "ab". This gives us the following array: ["aab", "ab", "cde", "ab", "aab"], which is palindromic.

Example 2

arr = ["palindrome"]return = 1

The given array is already palindromic, so no operations are needed.

Example 3

arr = ["aaaaaa", "aa"]return = 0

If moving two characters between two consecutive array elements was allowed, the array could have been made palindromic, but this is impossible given the actual rules.

Constraints

  • 1 ≤ arr.length ≤ 10^5
  • 2 ≤ arr[i].length ≤ 10

More PayPay interview questions

  • Next Greater Value in a Circular ArrayPHONE SCREEN · Seen Sep 2026
  • Sum Consecutive Identical DigitsOA · Seen Mar 2024
  • Calculate ChangeOA · Seen Feb 2022
  • Find Maximum Two-Digit FragmentPHONE SCREEN · Seen Sep 2021

Similar questions at other companies

  • Longest Subsequence which is a SubstringSalesforce · OASalesforce interview questions
  • Lexicographically Last SubstringRoblox · OARoblox interview questions
  • String CompressionAbridge · OAAbridge interview questions
  • Rearrange String by Alternating EndsHudson River Trading · OAHudson River Trading interview questions
  • Alternate String EndsCapital One · OACapital One interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions
  • Count Binary SubstringsMicrosoft · OAMicrosoft interview questions
  • Check a Repeated String as a SubsequenceQuince · OAQuince interview questions
  • Format TextTikTok · OATikTok interview questions
All PayPay interview questionsSee PayPay hiring insights
Saved
class Solution {
    public int solution(String[] arr) {
      // write your code here
    }

}
Checking account…