# String Mingling – HackerRank Solution

In this post, we will solve String Mingling HackerRank Solution. This problem (String Mingling) is a part of HackerRank Functional Programming series.

Contents

## Task

Pawel and Shaka recently became friends. They believe their friendship will last forever if they merge their favorite strings.

The lengths of their favorite strings are the same,Â n. Mingling two strings,Â P = p1p2 . . . pnÂ andÂ Q = q1q2 . . . qn, both of lengthÂ n, will result in the creation of a new stringÂ RÂ of lengthÂ 2 x n. It will have the following structure:

R = p1q1p2q2 . . . pnqn

You are given two stringsÂ PÂ (Pawel’s favorite) andÂ QÂ (Shaka’s favorite), determine the mingled stringÂ R.

## Input Format

The first line of input contains the stringÂ P.
The second line containsÂ Q.

## Output Format

Print the mingled string,Â R.

## Constraints

• 1 <= n <= 105
• The string only consists of lowercase English characters (az).
• length(P) = length(Q) = n

Sample Input #00

``````abcde
pqrst``````

Sample Output #00

``apbqcrdset``

Sample Input #01

``````hacker
ranker``````

Sample Output #01

``hraacnkkeerr``

Explanation

Sample Case #00:

P = a b c d e
Q = p q r s t
R = ap bq cr ds et

Sample Case #01:

P = h a c k e r
Q = r a n k e r
R = hr aa cn kk ee rr

## Solution – String Mingling – HackerRank Solution

Scala

```import java.util.Scanner

object Solution {
def main(args: Array[String]): Unit = {
val sc = new Scanner(System.in)
val p = sc.nextLine()
val q = sc.nextLine()

println(p.zip(q).map { case (a, b) => a.toString + b }.reduceLeft(_ + _))
}
}
```

Note: This problem (String Mingling) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.