All Tracks Problem

Random Words
Tag(s):

Easy, Implementation, Sorting, approved

Problem
Editorial
Analytics

Given $$N$$ words $$a_i$$ of lowercase letters. Arrange these words such that word $$a_i$$ of length $$l_i$$ comes before word $$a_j$$ of length $$l_j$$ if

1) $$l_i < l_j$$.
OR
2) $$l_i = l_j$$ and the first different letter in $$a_i$$ < corresponding letter in $$a_j$$. Letters are compared with respect to their ASCII Value.

For example: $$a_i$$ = "arm", $$a_j$$ = "ant", so "ant" comes before "arm" because second letter in $$a_j$$ $$(n)$$ < second letter in $$a_i$$ $$(r)$$.

Input:

In the first line: Given an integer $$N$$.
In the second line: $$N$$ strings $$a_i$$ follow.

Output:

Print the words in the order illustrated in the question.

Constraints:

$$1 \le N \le 100$$.
$$1 \le l_i \le 10$$.

SAMPLE INPUT
5
omar
apple
banana
ant
cat
SAMPLE OUTPUT
ant
cat
omar
apple
banana
Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

Fortinet

Challenge Name

Fortinet Fresher Hiring Challenge

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications