Alternate Print Problem Statement

Given two strings A and B, your task is to print these two strings in an alternating sequence by indices. That is, the first character of 'A', the first character of 'B', followed by the second character of 'A', the second character of 'B', and so on.

Example:

Input:
A = "abc", B = "fdh"
Output:
"afbdch"
Explanation:

The characters are alternated from both strings until all characters are used. If any characters are left in one string, they are appended at the end.

Constraints:

  • 1 <= T <= 10
  • 1 <= |A|, |B| <= 10^5
  • A and B contain only lowercase English letters.

Note:

If one string is exhausted and characters remain in the other, append the remaining characters of the other string to the end. You do not need to print anything; the function implementation will handle output.
Be the first one to answer
Add answer anonymously...
Bank of America Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter