Given an array of positive integers of size n. Reverse every sub-array group of size k(Full Question)

  • The start index which starts from 0 ans is incremented by k values on each iteration; it goes with values 0,k,2k...till n-1
  • The end index starts with start+k-1 index till n-1
  • This way the values are reversed in a window of k alone
void reverseInGroups(ArrayList<Integer> arr, int n, int k) {
for(int i=0;i<n;i+=k){
int start=i;
int end=Math.min(start+k-1,n-1);
// we handle cases where i+k goes out of bounds here
int temp=0;

Given a string s, reverse the string according to the following rules:

All the characters that are not English letters remain in the same position.

All the English letters (lowercase or uppercase) should be reversed.

Return s after reversing it.

Chaitra Rai

Intimidated developer trying to find her way into technology dominant world

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