Rookie Compare String Hackerrank Solution

Rookie Compare String Hackerrank Solution

1 min read

Given three strings, concatenate the strings in lexicographically increasing order to create a single string.

For example, given firstString = one, secondString = two, thirdString = three, concatenated in lexicographical order, the result = onethreetwo.

Function Description

Complete the function compareStrings in the editor below. The function must return a string.

compareStrings has the following parameter(s):

  • firstString: a string
  • secondString: a string
  • thirdString: a string

Input Format

The first line contains the first string The second line contains the second string The third line contains the third string

Constraints

  1. 1 ≤ |firstString|, |secondString|, |thirdString| ≤ 105
  2. Each of the strings consists of lowercase English characters, ascii[a-z].

Output Format

Output will be a concatenated string

Sample Input 0

hack
hacker
hackerrank

Sample Output 0

hackhackerhackerrank

Sample Input 1

klmno
abcde
fghij

Sample Output 1

abcdefghijklmno

Sample Input 2

ab
ac
aa

Sample Output 2

aaabac

Solution in Python

import math
import os
import random
import re
import sys

#
# Complete the 'compareStrings' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
#  1. STRING s1
#  2. STRING s2
#  3. STRING s3
#

def compareStrings(s1, s2, s3):
    # Write your code here
    d = []
    s = ""
    d.append(s1)
    d.append(s2)
    d.append(s3)
    d.sort()
    for i in d:
        s+=i
    return s

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    first_String = input()

    second_String = input()

    third_String = input()

    result = compareStrings(first_String, second_String, third_String)

    fptr.write(result + '\n')

    fptr.close()
Choose your Reaction!
Leave a Comment