PHP Compiler Testing
Lexicographically First and Last

Write a function that returns the lexicographically first and lexicographically last rearrangements of a lowercase string. Output the results in the following manner:

first_and_last(string) ➞ [first, last]

Examples

first_and_last("marmite") ➞ ["aeimmrt", "trmmiea"]

 

first_and_last("bench") ➞ ["bcehn", "nhecb"]

 

first_and_last("scoop") ➞ ["coops", "spooc"]