Skip to main content
4 of 5
deleted 237 characters in body
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 10, 161 159 152 bytes

s->{var x="";int p=0;for(var c:s)x+=p<(p=c)?c:";"+c;for(var y:x.split(";"))System.out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ".replaceAll("[^"+y+"]"," "));}

-2 bytes thanks to @Nevay.
-7 byte printing directly instead of returning a String, and converting to Java 10.

Explanation:"

Try it here.

s->{                      // Method with String parameter and no return-type
  var x="";               //  Temp-String
  int p=0;                //  Previous character (as integer), starting at 0
  for(var c:s)            //  Loop (1) over the characters of the input
    x+=p<(p=c)?           //   If the current character is later in the alphabet
                          //   (replace previous `p` with current `c` afterwards)
        c                 //    Append the current character to Temp-String `x`
       :                  //   Else:
        ";"+c;            //    Append a delimiter ";" + this character to Temp-String `x`
  for(var y:x.split(";")) //  Loop (2) over the String-parts
    System.out.println(   //   Print, with trailing new-line:
     "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                          //    Take the alphabet,
        .replaceAll("[^"+y+"]"," "));}
                          //    and replace all letters not in the String-part with a space

The first part of the method splits the input-word into parts with a delimiter.
For example: CODEGOLFCO;DEGO;L;F or BALLOONB;AL;LO;O;N.

The second part loops over these parts, and uses the regex [^...] to replace everything that isn't matched with a space.
For example .replaceAll("[^CO]"," ") leaves the C, and O, and replaces everything else with a space.

Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384