...

/

Merge Two Sorted Strings Lexicographically

Merge Two Sorted Strings Lexicographically

In this lesson, we'll learn how to merge two strings lexicographically.

What does “Merging Two Sorted Strings Lexicographically” Mean?

Lexicographical means that something is organized according to alphabetical order.

Lower case letters are different from upper case letters and are therefore treated as different elements. All upper case letters come before lower case letters. Alphabetic sorting is as follows: $A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z$

In this task, we’re merging two strings (that are themselves sorted). Have a look at the illustration below:

Merging strings lexicographically.
Merging strings lexicographically.

Implementation

The input strings are already sorted. We need to merge the two strings in a way that the output string is also sorted.

In Javascript, an alphabet can be compared with another alphabet. This means that 'a' < 'b', 'b' < 'c', 'c' < 'd' and so on.