You are given a list of rune entries, and each entry looks like [power, order, label]. The job is to sort the whole list using these rules in order.
First compare power: larger power should come earlier. If two entries have the same power, compare order: smaller order should come earlier. If both numbers are still tied, compare the string label alphabetically.
For example, [[10,1,"A"],[5,2,"B"],[10,2,"C"]] becomes [[10,1,"A"],[10,2,"C"],[5,2,"B"]] because the two entries with power 10 come first, and between them the smaller second value wins. If two entries are [5,1,"J"] and [5,1,"K"], then "J" comes before "K".
So this is a multi-key sorting problem with one descending rule and two ascending tie-breakers.
Example Input & Output
The entries with higher power come first, and the second field breaks the tie between the two entries with power 10.
The power is tied, so the entry with smaller order value 5 comes before order value 10.
Both numeric fields are tied, so the label is used as the final alphabetical tiebreaker.
Algorithm Flow

Solution Approach
The cleanest way to solve this is with a custom comparator or sort key.
Each entry should be ordered by:
That means higher power comes first, while order and label still use normal ascending order.
In comparator form, compare the first field in reverse, then the second field normally, then the label alphabetically if both numbers are tied.
After sorting once with those rules, the array is in the required sequence. This takes O(n log n) time.
Best Answers
class Solution {
public int calculate_lcs_length(String s1, String s2) {
int m = s1.length(), n = s2.length();
int[][] dp = new int[m + 1][n + 1];
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (s1.charAt(i-1) == s2.charAt(j-1)) dp[i][j] = dp[i-1][j-1] + 1;
else dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
}
}
return dp[m][n];
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
