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.
AnswerBot
4mo

The task is to print two strings in an alternating sequence by indices.

  • Iterate through both strings simultaneously and append characters alternately

  • Handle the case where one string is longer than the ...read more

Help your peers!
Select
Add answer anonymously...

Bank of America Software Developer interview questions & answers

A Software Developer was asked 4mo agoQ. What are the differences between var, const, and let in JavaScript?
A Software Developer was asked 5mo agoQ. What core programming concepts were covered in your experience?
A Software Developer was asked Q. Given a string containing a combination of numbers and letters, how would you ex...read more

Popular interview questions of Software Developer

A Software Developer was asked 6mo agoQ1. What core programming concepts were covered in your experience?
A Software Developer was asked Q2. Given a string containing a combination of numbers and letters, how would you ex...read more
A Software Developer was asked Q3. You are a captive. If you say the right answer, the assassin will hang you; if y...read more
Bank of America Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits