Rotate Array|Coding Problems

/* author : @akash */#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define ld long double
void solve()
{
int n,d;
cin>>n>>d;
int a[n];
for(int i=0;i<n;++i)
{
cin>>a[i];
}
for(int i=0;i<d;++i)
{
int tmp=a[0];
for(int j=1;j<n;++j)
{
a[j-1]=a[j];
}
a[n-1]=tmp;
}
for(int i=0;i<n;++i)
{
cout<<a[i]<<" ";
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
cout<<"\n";
}
return 0;
}
// time complexity of this algorithm is : T(n)=O(n*d)

--

--

--

Student of Computer Science & Engineering at Moradabad Institute of Technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Ad insertion on VOD and Live Media Content using AWS MediaTailor and CloudFront

How to use Spring JdbcTemplate

How to Hire Android Developers

Reddit Web Scraping & Data Analysis Walkthrough

Announcing Monolith #1: Authoritative API3 DAO

PERSONAL INFRASTRUCTURES

Showing Bar Chart in Android using Kotlin (an Agrego Seller case)

Picture of Himalayan mountain

Increasing Test Reliability in Python through Object Mocking

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akash Kumar

Akash Kumar

Student of Computer Science & Engineering at Moradabad Institute of Technology.

More from Medium

Incremental and Iterative Development

Top 10 Email Tracking Software and Extensions for Gmail in 2022

Superlative Advantages of Binary MLM Software

Thinkific Alternatives: Our Top 6 Best Picks