Let us define a transformation that, given a string S of letters 'a' and/or 'b', replaces some consecutive sequence "abb" in S by "baa".
For example, after applying such a transformation to the string "abbabb", both strings "baaabb" and "abbbaa" can be obtained.
Write a function:
func Solution(S string) string
that, given a string S of length N, returns the alphabetically largest string that can be obtained by performing the above operation any number of times.
Examples:
1. Given S = "ababb", your function should return "baaaa".
"baaaa" is alphabetically the largest possible outcome and may be obtained from "ababb" by using two transformations:
"ababb" → "abbaa" → "baaaa"
2. Given S = "abbbabb", your function should return "babaaaa".
"babaaaa" may be obtained from "abbbabb" by using three transformations:
"abbbabb" → "abbbbaa" → "baabbaa" → "babaaaa"
3. Given S = "aaabab", your function should return "aaabab".
No operation can be performed on S since it contains no "abb" fragment.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- string S is made only of the characters 'a' and/or 'b'.
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v =
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune()
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune(a)
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a")
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a"){}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && r{
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S){
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2{
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] =={
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] =="b" && {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] =="b" && S[i+1] == {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] =="b" && S[i+2] == {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] =="b" && S[i+2] =="b" {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b" && S[i+2] =="b" {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
S[]
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
S[i] =
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
S[i] =
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range S {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
S[i] =
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] =
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i] = rune("b")
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(S)
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(string(s))
}
}
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(string(s))
}
}
return string
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == rune("a") && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(string(s))
}
}
return string(s)
}
# solution workspace/src/solution/solution.go:14: cannot convert "a" to type rune workspace/src/solution/solution.go:14: cannot convert "a" (type string) to type rune workspace/src/solution/solution.go:14: invalid operation: v == "a" (mismatched types rune and string) workspace/src/solution/solution.go:14: cannot convert "b" to type rune workspace/src/solution/solution.go:14: cannot convert "b" (type string) to type rune workspace/src/solution/solution.go:14: invalid operation: S[i + 1] == "b" (mismatched types uint8 and string) workspace/src/solution/solution.go:14: cannot convert "b" to type rune workspace/src/solution/solution.go:14: cannot convert "b" (type string) to type rune workspace/src/solution/solution.go:14: invalid operation: S[i + 2] == "b" (mismatched types uint8 and string) workspace/src/solution/solution.go:15: cannot convert "b" to type rune workspace/src/solution/solution.go:15: too many errors
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == && i < len(S)-2 && S[i+1] ==rune("b") && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(S)-2 && S[i+1] =='b' && S[i+2] ==rune("b") {
s[i] = rune("b")
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(S)-2 && S[i+1] =='b' && S[i+2] =='b' {
s[i] = 'b'
s[i+1] = rune("a")
s[i+2] = rune("a")
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(S)-2 && S[i+1] =='b' && S[i+2] =='b' {
s[i] = 'b'
s[i+1] = 'a'
s[i+2] = 'a'
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(S)-2 && S[i+1] =='b' && S[i+2] =='b' {
s[i] = 'b'
s[i+1] = 'a'
s[i+2] = 'a'
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(s)-2 && S[i+1] =='b' && S[i+2] =='b' {
s[i] = 'b'
s[i+1] = 'a'
s[i+2] = 'a'
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(s)-2 && s[i+1] =='b' && s[i+2] =='b' {
s[i] = 'b'
s[i+1] = 'a'
s[i+2] = 'a'
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(s)-2 && s[i+1] =='b' && s[i+2] =='b' {
s[i] = 'b'
s[i+1] = 'a'
s[i+2] = 'a'
return Solution(string(s))
}
}
return string(s)
}
package solution
// you can also use imports, for example:
// import "fmt"
// import "os"
// you can write to stdout for debugging purposes, e.g.
// fmt.Println("this is a debug message")
func Solution(S string) string {
// write your code in Go 1.4
s := []rune(S)
for i,v := range s {
if v == 'a' && i < len(s)-2 && s[i+1] =='b' && s[i+2] =='b' {
s[i] = 'b'
s[i+1] = 'a'
s[i+2] = 'a'
return Solution(string(s))
}
}
return string(s)
}
The following issues have been detected: timeout errors.
Simple big test. N = 100,000. Score x 3.
Killed. Hard limit reached: 6.000 sec.