Skip to content

Commit 20e7b55

Browse files
authored
DSA : HackerRank
1 parent a6fe726 commit 20e7b55

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Array-Left-Rotation.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
vector<int> rotLeft(vector<int> a, int d) {
2+
int r = 0 ;
3+
vector<int> result ;
4+
if (a.size() <= d )
5+
{
6+
r = d ;
7+
}
8+
else
9+
{
10+
r = d % a.size();
11+
}
12+
for (int i = r ; i < a.size() ; i++) {
13+
result.push_back(a[i]);
14+
}
15+
for (int j = 0 ; j < r; j++) {
16+
result.push_back(a[j]);
17+
}
18+
return result;
19+
}

0 commit comments

Comments
 (0)