Skip to content

Commit 235fc36

Browse files
authored
Merge pull request #346 from sir-gon/develop
[REFACTOR] copy slice to avoid mutate input
2 parents d5c4e56 + b5f7629 commit 235fc36

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

exercises/hackerrank/interview_preparation_kit/arrays/ctci_array_left_rotation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ func rotLeftOne(a []int32) []int32 {
1515
}
1616

1717
func rotLeft(a []int32, d int32) []int32 {
18-
x := a[:]
18+
// Sort the array
19+
x := make([]int32, len(a))
20+
copy(x, a)
1921

2022
for range d {
2123
x = rotLeftOne(x)

0 commit comments

Comments
 (0)