QP6V7XUIVGGIBHEVTUQBLC7R7WGS6QVYGZRHLVX7TLETV6E5HYTQC
// Package transpose...
package transpose
import (
"strings"
)
// Transpose transposes input string slice.
func Transpose(input []string) []string {
if len(input) == 0 {
return []string{}
}
var longestLine int
for _, line := range input {
if len(line) > longestLine {
longestLine = len(line)
}
}
ret := make([]strings.Builder, longestLine)
for i, line := range input {
for k, ch := range line {
ret[k].WriteString(strings.Repeat(" ", i-ret[k].Len()))
ret[k].WriteRune(ch)
}
}
r := make([]string, len(ret))
for i := range ret {
r[i] = ret[i].String()
}
return r
}