FastPrepRearrange String
Problems/Rearrange String

Rearrange String

Intuit logoIntuit● HardOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You have a string S. Your task is to rearrange some characters of the string (if needed) so that S[i] is not equal to S[L - i - 1] for each 0 <= i < (L - 1) / 2, where L is the length of S. If multiple rearrangements exist, return the one that comes earliest alphabetically. If there is no answer, print 'impossible.'

Input

The input contains the string S.

Output

Print 'impossible' if there is no answer. Otherwise, print a lexicographical first string that satisfies the given requirements.

Function

rearrangeString(s: String) → String

Examples

Example 1

s = "abca"return = "aabc"

No explanation is provided for now 😳🔫 As always, I will add it once find any. Or if you happen to know about it, feel free to dm Groot! Many thanks in advance! 🫶

Constraints

  • 1 <= L <= 10^4

More Intuit interview questions

  • Number of IslandsONSITE INTERVIEW · Seen Nov 2026
  • VIP and Regular Service SchedulerPHONE SCREEN · Seen Nov 2026
  • 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

Similar questions at other companies

  • Lexicographically Largest IdentifierAmazon · OA
  • Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
  • Binary CircuitAkuna Capital · OAAkuna Capital interview questions
  • Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
  • Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
  • Palindromic StringsNVIDIA · OANVIDIA interview questions
  • Get Patch SequenceMorgan Stanley · OAMorgan Stanley interview questions
  • Max Number of OperationsSalesforce · OASalesforce interview questions
  • Viral Content BalancerTikTok · OATikTok interview questions
  • Good Binary StringsBNP Paribas · OA

Interview reports that mention this question

  • Intuit OA: What It Tests (2026)

Intuit interview experiences

  • Intuit Software Engineering Intern - Full Stack OA Format
All Intuit interview questionsSee Intuit hiring insights
Saved
class Solution {
    public String rearrangeString(String s) {
        // write your code here
    }

}
Checking account…