The Third Smallest Number
InterviewTime limit1sMemory limit128 MB
Given n distinct natural numbers, list all two-element ordered concatenations by value and report the third smallest.
- Level
Medium6 of 10
- Topics
- String, Sorting, Greedy, Brute force
- Solved
- No attempts yet
Problem
You are given distinct natural numbers . By choosing two of them in order — that is, picking two distinct indices , placing in front and behind — and concatenating them, you can form a new number.
For example, concatenating and gives or . Likewise, for and , the results and are counted as different results (because the concatenation order differs), even when their values coincide (both equal here).
List every number that can be formed this way in nondecreasing order, counting each equal value as many times as it occurs. Write a program that prints the third smallest number in this list.
Input
The first line contains the count of numbers (). Each of the next lines contains one (). The given numbers are all distinct.
Output
Print the third smallest number on a single line.