From 409bc84aab946c3f9c88665d0051e7a7ff4ae75a Mon Sep 17 00:00:00 2001 From: Saravanan Date: Sun, 6 Oct 2024 03:08:55 +0100 Subject: [PATCH 1/2] Issue fix --- src/.DS_Store | Bin 0 -> 6148 bytes src/com/.DS_Store | Bin 0 -> 6148 bytes src/com/array/rotations/ArrayRotation.java | 62 +++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/.DS_Store create mode 100644 src/com/.DS_Store create mode 100644 src/com/array/rotations/ArrayRotation.java diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T09MNA*4w8fD}kH zRQUs_X`!G%d;wn(<;~2R?B>oU6^hV~wENDxZ+G9l^UZoqM5Z+xG>Ga%R6}8mR#BA% z_j4)4if!2f8ku84N0g3+jZQx+utP&|AUJT}9N>4iinsPP%8;D*Hyx|gCohVOG;6ne zqpXLX+NZ0}-5<}t?v$|xcVLZQa<-VSmS7sHK+8n5oN6wa_f~)Uy{?Y#t9QRP4n&7D zKFw}4lr#MGIS(S)^`KxRuJq}c2EK~TW*NuT^5yd4>38*{Fqf-n8PC_Xt-AV@(G1UO zN++m?zOLwl=(@#mbv2)Td%vz8)u_O`acUXQ*Cl?f(pdarO#?i)j8Z!GwXK~)TPe@e z_xtQIslEkVN8?|(zRraGtBB4Cy}7L}dh7SPn)ddmA0N%XSA3r`-hGPY41ay`i8b7( zz@E)fd#D)d;6QL7IPk{-&JQsPV`4E^l+=MrjsU<2%@VklTnCJ~0hn0K714q)Iuxiw zjXh!*9gg7LZg-#|>40UiIIN&?*KtI-b|KDAF{`Uuk zPr-rUz<=d{iQ1iZ3%6wV*22y4UK^tvqHr)TSCk>B>~<^{ycP5R3KHmx`2v_&%oWjs P2tNeGhEN3u{;31k$hgp( literal 0 HcmV?d00001 diff --git a/src/com/array/rotations/ArrayRotation.java b/src/com/array/rotations/ArrayRotation.java new file mode 100644 index 0000000..d96e7e4 --- /dev/null +++ b/src/com/array/rotations/ArrayRotation.java @@ -0,0 +1,62 @@ +package com.array.rotations; + +public class ArrayRotation { + public static void rotateRight(int[] arr, int n) { + int len = arr.length; + if (len == 0 || n % len == 0) { + return; // No rotation needed + } + n = n % len; // To handle n greater than length + reverse(arr, 0, len - 1); // Reverse the whole array + reverse(arr, 0, n - 1); // Reverse the first part + reverse(arr, n, len - 1); // Reverse the second part + } + + // Method to rotate an array to the left by n positions + public static void rotateLeft(int[] arr, int n) { + int len = arr.length; + if (len == 0 || n % len == 0) { + return; // No rotation needed + } + n = n % len; // To handle n greater than length + reverse(arr, 0, n - 1); // Reverse the first part + reverse(arr, n, len - 1); // Reverse the second part + reverse(arr, 0, len - 1); // Reverse the whole array + } + + // Helper method to reverse elements in an array between two indices + private static void reverse(int[] arr, int start, int end) { + while (start < end) { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + // Utility method to print the array + public static void printArray(int[] arr) { + for (int num : arr) { + System.out.print(num + " "); + } + System.out.println(); + } + + public static void main(String[] args) { + int[] arrRight = {1, 2, 3, 4, 5}; + int[] arrLeft = {1, 2, 3, 4, 5}; + int n = 2; + + System.out.println("Original array:"); + printArray(arrRight); + + rotateRight(arrRight, n); + System.out.println("Array after right rotation by " + n + " positions:"); + printArray(arrRight); + + rotateLeft(arrLeft, n); + System.out.println("Array after left rotation by " + n + " positions:"); + printArray(arrLeft); + } +} From 963c8d6f5afa025c0031f82f5639133effea469e Mon Sep 17 00:00:00 2001 From: Saravanan Date: Fri, 21 Jul 2023 12:33:41 +0100 Subject: [PATCH 2/2] Past commit --- file-new.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 file-new.txt diff --git a/file-new.txt b/file-new.txt new file mode 100644 index 0000000..5852f44 --- /dev/null +++ b/file-new.txt @@ -0,0 +1 @@ +Initial commit