Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6369683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:50:10+00:00 2026-05-25T00:50:10+00:00

This is an interview question. Given a string such as: 123456abcdef consisting of n/2

  • 0

This is an interview question.

Given a string such as: 123456abcdef consisting of n/2 integers followed by n/2 characters. Reorder the string to contain as 1a2b3c4d5e6f . The algortithm should be in-place.

The solution I gave was trivial – O(n^2). Just shift the characters by n/2 places to the left.

I tried using recursion as –
a. Swap later half of the first half with the previous half of the 2nd part – eg
123 456 abc def
123 abc 456 def
b. Recurse on the two halves.

The pbm I am stuck is that the swapping varies with the number of elements – for eg.

What to do next?
123 abc
12ab 3c

And what to do for : 12345 abcde
123abc 45ab

This is a pretty old question and may be a duplicate. Please let me know.. 🙂

Another example:
Input: 38726zfgsa
Output: 3z8f7g2s6a

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:50:11+00:00Added an answer on May 25, 2026 at 12:50 am

    Here’s how I would approach the problem:

    1) Divide the string into two partitions, number part and letter part
    2) Divide each of those partitions into two more (equal sized)
    3) Swap the second the third partition (inner number and inner letter)
    4) Recurse on the original two partitions (with their newly swapped bits)
    5) Stop when the partition has a size of 2
    

    For example:

    123456abcdef -> 123456 abcdef -> 123 456 abc def -> 123 abc 456 def

    123abc -> 123 abc -> 12 3 ab c -> 12 ab 3 c

    12 ab -> 1 2 a b -> 1 a 2 b

    … etc

    And the same for the other half of the recursion..

    All can be done in place with the only gotcha being swapping partitions that aren’t the same size (but it’ll be off by one, so not difficult to handle).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an interview question : Given 2 integers x and y, check if
I saw this in an interview question , Given a sorting order string, you
This is an interview question: Given a string, find all its permutations that are
In an pre-interview, I am faced with a question like this: Given a string
This was an interview question. Given Visual Studio 2008 and an icon saved as
This is an interview question I faced recently. Given an array of 1 and
I was given this interview question recently: Given a 12-hour analog clock, compute in
I am trying to code a trival interview question of reversing a string. This
I had this question: Given an unsorted array of positive integers and an integer
I came across this post , which reports the following interview question: Given two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.