Sobes.tech
Junior — Senior

Sorting an array of strings with priority for characters «s» and «k»

livecode

Task condition

Given an array of strings. It is required to sort it according to the following rules:

  1. Strings equal to "s" and "k" should be at the beginning of the array (the order between them is not important);
  2. The remaining strings are sorted lexicographically;
  3. The original array may contain any lowercase letters.
public class Main{
    public static void main(String[] args){
        List<String> list = List.of("f", "z", "y", "e", "b", "i", "g", "a", "k", "h", "s", "w");
    }
}