You will Understand Question and Solution | Java Solution | Easy Explaination
Let\'s try to Understand Question first-\n\nQuestion is asking us to sort the logs based on its content in lexographical order, if content is same then we have 
**Let\'s try to Understand Question first-**\n\nQuestion is asking us to sort the logs based on its content in lexographical order, if content is same then we have to sort based on their version name.\n\n1. How to identify if it is letter-log?\n\t-> If second word in sentence is word then it is letter-log.\n2. How to identify if it digit-log?\n\t-> If second word in sentence is number then it is digit-log.\n\t\nOnce we identify letter log, **We have to sort letter-logs based on their content which is except first word lexicographically, if their content is same then we need to sort them based on their names which is first word**.\n\nAfter sorting we have to keep the **letter-logs first in result**, then we can store **digits-logs in their original input order**.\n\nHope, Question is clear.\n\n**Solution :**\n```\nclass Solution {\n    public String[] reorderLogFiles(String[] logs) {\n        \n        int n = logs.length;\n        \n\t\t// we will store letter-logs so that we can sort them independently\n        List<String> letterLogs = new ArrayList<>();\n        List<String> result = new ArrayList<>();\n        \n        for(int i=0;i<n;i++){\n            if(!isDigitLogs(logs[i])){\n                letterLogs.add(logs[i]);\n            }\n        }\n        \n\t\t// Here we are sorting \n        Collections.sort(letterLogs,(s1,s2)->{\n            String exceptFirstWord_ofS1 = s1.split(" ", 2)[1];  // only content of sentence will be there\n            String exceptFirstWord_ofS2 = s2.split(" ", 2)[1];  // only content of sentence will be there\n            \n\t\t\t// if the content is same then we are using full word to sort else the content alone\n            return exceptFirstWord_ofS1.equals(exceptFirstWord_ofS2)?s1.compareTo(s2):exceptFirstWord_ofS1.compareTo(exceptFirstWord_ofS2);\n        });\n        \n\t\t// lets add the letter logs first\n        for(String letterLog : letterLogs){\n            result.add(letterLog);\n        }\n        \n\t\t// lets add digit logs \n        for(int i=0;i<n;i++){\n            if(isDigitLogs(logs[i])){\n                result.add(logs[i]);\n            }\n        }\n        \n        return result.toArray(new String[0]);\n    }\n    \n\t// return true if it is digit log\n    public boolean isDigitLogs(String s){\n        String secondWord = s.split(" ")[1];\n        if(secondWord.charAt(0)>=\'0\' && secondWord.charAt(0)<=\'9\')\n            return true;\n        return false;\n    }\n}\n```\n\n**Suggestions are always welcome!!**
['Java']