Please anyone help me with why the program turns to output wrong answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please anyone help me with why the program turns to output wrong answer

Question: Lets make a dictionary order (100 Marks) You need to input N words one on each line and output should be lexicographically sorted i.e the words which comes as a output should be lexicographically sorted Input Format You will be taking an integer N from STDIN. Following N lines contains string one on each line. Constraints 1 < N < 10000 1 < |S| < 1000 Output Format The words should be lexicographically sorted and should be displayed one per each line. Sample TestCase 1 Input 10 fortran java perl python php javascript c cpp ruby csharp Output c cpp csharp fortran java javascript perl php python ruby Explanation In mathematics, the lexicographic or lexicographical order (also known as lexical order, dictionary order, alphabetical order or lexicographical product) is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters. Time Limit(X): 1.00 sec(s) for each input. Memory Limit: 512 MB Source Limit: 100 KB My code : https://ide.geeksforgeeks.org/qv6UND3ZJw When i run with my inputs it runs and gives correct output but when submitting it gives that it is a wrong answer. So could you please tell me what the problem would be .

17th Feb 2019, 7:22 AM
Balaji Pathange
Balaji Pathange - avatar
1 Answer
+ 4
When I checked it for 40 inputs it took 1.4794191156006 seconds to execute. Also, the string length given by you is 50 and in the question, constraint is of 1000. Try a faster sorting operation like quick sort or binary sort.
4th Jul 2020, 5:41 PM
Prabhanshu Chaturvedi