Created
August 5, 2022 12:52
-
-
Save kotakagi0914/56044bd5df5918692ad69aae2d2b6849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func getIndices(intList []int) [2]int { | |
indices := [2]int{} | |
brokenIndex := 0 | |
for i := 1; i < len(intList)-1; i++ { | |
if intList[i-1] > intList[i] { | |
brokenIndex = i | |
break | |
} | |
} | |
for i := brokenIndex - 1; i > 0; i-- { | |
if intList[brokenIndex] >= intList[i] { | |
indices[0] = i | |
break | |
} | |
} | |
for i := len(intList) - 2; i > 1; i-- { | |
if intList[i] > intList[i+1] { | |
brokenIndex = i | |
break | |
} | |
} | |
for i := brokenIndex + 1; i < len(intList); i++ { | |
if intList[brokenIndex] <= intList[i] { | |
indices[1] = i - 1 | |
break | |
} | |
} | |
return indices | |
} | |
func main() { | |
fmt.Println(getIndices([]int{1, 2, 4, 7, 10, 11, 7, 12, 6, 7, 16, 18, 19})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment