Two solutions | Easy to understand | Java | 100%
\nAlgo 1: Separate both the logs and sort letter logs\n\n\n\n\n/**\n * Separate both the logs and sort letter logs\n * Time Complexity:\n * n -> Length of logs 
\n**Algo 1: Separate both the logs and sort letter logs**\n\n```\n\n\n/**\n * Separate both the logs and sort letter logs\n * Time Complexity:\n * n -> Length of logs array\n * L -> length of letter logs array\n * D -> length of digit logs array\n * Sorting  L length array is O(L*log(L))\n * <p>\n * Overall : O(n) + O(L*log(L)) + O(n) => O(L*log(L)) > O(n)\n * <p>\n * In worst case: n == L hence O(n*log(n))\n * Runtime: 37 ms, faster than 32.53% of Java online submissions for Reorder Data in Log Files.\n * Memory Usage: 38.6 MB, less than 73.53% of Java online submissions for Reorder Data in Log Files.\n */\nclass ReorderDataLogFilesSeparateSortIndexOf {\n    public String[] reorderLogFiles(String[] logs) {\n\n        if (logs == null || logs.length == 0)\n            return logs;\n\n        final List<String> digitLogs = new ArrayList<>();\n        final List<String> letterLogs = new ArrayList<>();\n\n        for (String log : logs) {\n\n            int ind = log.indexOf(\' \');\n            char c = log.charAt(ind + 1);\n\n\n            //is digit logs\n            if (c >= \'0\' && c <= \'9\')\n                digitLogs.add(log);\n            else\n                letterLogs.add(log);\n        }\n\n        final Comparator<String> com = (o1, o2) -> {\n            //if words after identifier are same , the sort based on identifier\n            String[] split1 = o1.split(" ", 2);\n            String[] split2 = o2.split(" ", 2);\n\n            if (split1[1].compareTo(split2[1]) == 0)\n                return split1[0].compareTo(split2[0]);\n\n            return split1[1].compareTo(split2[1]); ////the sort based on words\n        };\n\n        letterLogs.sort(com);\n\n        letterLogs.addAll(digitLogs);\n        String[] output = new String[letterLogs.size()];\n        int i = 0;\n        for (String s : letterLogs)\n            output[i++] = s;\n\n        return output;\n    }\n}\n\n```\n\n**Algo 2:**\nSort within , as we just need to sort based on first char of word\n```\n\n/**\n * Runtime: 2 ms, faster than 99.33% of Java online submissions for Reorder Data in Log Files.\n * Memory Usage: 38.8 MB, less than 70.59% of Java online submissions for Reorder Data in Log Files.\n */\nclass ReorderDataLogFilesWithInSortIndexOf {\n    public String[] reorderLogFiles(String[] logs) {\n\n        if (logs == null || logs.length == 0)\n            return logs;\n\n        Comparator<String> com = new Comparator<String>() {\n\n            @Override\n            public int compare(String o1, String o2) {\n                int ind1 = o1.indexOf(\' \');\n                char c1 = o1.charAt(ind1 + 1);\n\n                int ind2 = o2.indexOf(\' \');\n                char c2 = o2.charAt(ind2 + 1);\n\n\n                if (c1 >= \'0\' && c1 <= \'9\') {\n                    if (c2 >= \'0\' && c2 <= \'9\')\n                        return 0; //if both are digit, then their should not be any sorting,  hence mark them equal.=> 0\n                    else\n                        return 1; // Otherwise gives non-digit logs as higher priority\n                }\n                if (c2 >= \'0\' && c2 <= \'9\')\n                    return -1; // Otherwise gives non-digit logs as higher priority\n\n                String s1 = o1.substring(ind1 + 1);\n                String s2 = o2.substring(ind2 + 1);\n\n\n                int comp = s1.compareTo(s2);\n                if (comp == 0) {\n                    String s1ID = o1.substring(0, ind1);\n                    String s2ID = o2.substring(0, ind2);\n                    return s1ID.compareTo(s2ID);\n                }\n\n                return comp; ////the sort based on words\n            }\n        };\n\n\n        Arrays.sort(logs, com);\n\n        return logs;\n    }\n}\n```
[]