From d12411fc0593b19928cf9943074d47e180ddfafb Mon Sep 17 00:00:00 2001 From: Saravanan Date: Fri, 7 Jul 2023 12:33:41 +0100 Subject: [PATCH 1/6] Past commit --- test2.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 test2.txt diff --git a/test2.txt b/test2.txt new file mode 100644 index 0000000..5852f44 --- /dev/null +++ b/test2.txt @@ -0,0 +1 @@ +Initial commit From a41c9e038911ee9ab341979b49af10e3a8cf9950 Mon Sep 17 00:00:00 2001 From: Saravanan Date: Fri, 11 Aug 2023 12:33:41 +0100 Subject: [PATCH 2/6] Past commit --- file2.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 file2.txt diff --git a/file2.txt b/file2.txt new file mode 100644 index 0000000..5852f44 --- /dev/null +++ b/file2.txt @@ -0,0 +1 @@ +Initial commit From 3d7862693306aa0073b62131a714373374d98d9c Mon Sep 17 00:00:00 2001 From: Saravanan Date: Thu, 24 Aug 2023 12:33:41 +0100 Subject: [PATCH 3/6] Past commit --- file4.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 file4.txt diff --git a/file4.txt b/file4.txt new file mode 100644 index 0000000..5852f44 --- /dev/null +++ b/file4.txt @@ -0,0 +1 @@ +Initial commit From aa31844ed3715332c31eca5e40e1a1b988b89f38 Mon Sep 17 00:00:00 2001 From: Saravanan Date: Sat, 2 Sep 2023 12:33:41 +0100 Subject: [PATCH 4/6] Past commit --- file2.txt | 1 - file3.txt | 1 - file4.txt | 1 - src/com/array/rotations/SubArraySample.java | 89 +++++++++++++++++++++ file1.txt => test.txt | 0 5 files changed, 89 insertions(+), 3 deletions(-) delete mode 100644 file2.txt delete mode 100644 file3.txt delete mode 100644 file4.txt create mode 100644 src/com/array/rotations/SubArraySample.java rename file1.txt => test.txt (100%) diff --git a/file2.txt b/file2.txt deleted file mode 100644 index 5852f44..0000000 --- a/file2.txt +++ /dev/null @@ -1 +0,0 @@ -Initial commit diff --git a/file3.txt b/file3.txt deleted file mode 100644 index 5852f44..0000000 --- a/file3.txt +++ /dev/null @@ -1 +0,0 @@ -Initial commit diff --git a/file4.txt b/file4.txt deleted file mode 100644 index 5852f44..0000000 --- a/file4.txt +++ /dev/null @@ -1 +0,0 @@ -Initial commit diff --git a/src/com/array/rotations/SubArraySample.java b/src/com/array/rotations/SubArraySample.java new file mode 100644 index 0000000..a0d0024 --- /dev/null +++ b/src/com/array/rotations/SubArraySample.java @@ -0,0 +1,89 @@ +package com.array.rotations; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class SubArraySample { + + // Create in integer array (1,...10) + // input n = 2 + // output should be [1,2] [3,4] + + + public static void main(String arg[]) { + List ll = Arrays.asList(1,5,2,3, 5,4,6,1,7, 8,2,9, 3,4); + int n =5; + System.out.println( + IntStream + .range(0, (ll.size() + n - 1) / n) + .mapToObj(i -> ll.subList(i * n, Math.min((i + 1) * n, ll.size()))) + .collect(Collectors.toList())); + + List> result = null;//getSubArray(ll, n); + //result.forEach(System.out::println); + } + + private static List> getSubArray(List ll, int n) { + + List> result = new ArrayList<>(); + List subArray = new ArrayList<>(); + for (Integer num : ll) { + subArray.add(num); + if(subArray.size() == n) { + result.add(subArray); + subArray = new ArrayList<>(); + } + } + + if(!subArray.isEmpty()) { + result.add(subArray); + } + + + return IntStream + .range(0, (ll.size() + n - 1) / n) + .mapToObj(i -> ll.subList(i * n, Math.min((i + 1) * n, ll.size()))) + .collect(Collectors.toList()); + + //return result; + } + + public static void main1(String arg[]) { + List ll = Arrays.asList(1,5,2,3, 5,4,6,1,7, 8,2,9, 3,4); + int n =2; + List> sequences = subArrayBasedOnIndex(ll, n); + sequences.forEach(System.out::println); + + List finalResult = sequences + .stream() + .flatMap(list->list.parallelStream()) + .sorted(Comparator.reverseOrder()) + .collect(Collectors.toList()); + + System.out.println(finalResult); + } + + private static List> subArrayBasedOnIndex(List ll, int n) { + List> sequences = new ArrayList<>(); + List subSeq = new ArrayList<>(); + + for (int index=0; index < ll.size() ; index++) { + subSeq.add(ll.get(index)); + if(subSeq.size() == n) { + sequences.add(subSeq); + subSeq = new ArrayList<>(); + } + } + + if(!subSeq.isEmpty()) { + sequences.add(subSeq); + } + + return sequences; + } + +} diff --git a/file1.txt b/test.txt similarity index 100% rename from file1.txt rename to test.txt From f31261533d1b693b0544e8003ab7d4acfb1d3b72 Mon Sep 17 00:00:00 2001 From: Saravanan Date: Thu, 7 Sep 2023 12:33:41 +0100 Subject: [PATCH 5/6] Past commit --- src/com/array/rotations/PeekSample.java | 29 +++++++++++++++++++++++++ test1.txt | 1 + 2 files changed, 30 insertions(+) create mode 100644 src/com/array/rotations/PeekSample.java create mode 100644 test1.txt diff --git a/src/com/array/rotations/PeekSample.java b/src/com/array/rotations/PeekSample.java new file mode 100644 index 0000000..d017eeb --- /dev/null +++ b/src/com/array/rotations/PeekSample.java @@ -0,0 +1,29 @@ +package com.array.rotations; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class PeekSample { + + public static void main(String arg[]) { + List names = Arrays.asList("Alice", "Bob", "Charlie", "David", "Edward"); + + List upperNames = names + .stream() + .peek(n-> System.out.println("Names : "+n)) + //.map(n-> n) + .collect(Collectors.toList()); + + upperNames.stream().forEach(n -> System.out.println(n)); + + String listToString = upperNames + .stream() + //.map(n->n) + .collect(Collectors.joining(", ", "[", "]")); + + + System.out.println(listToString); + } + +} diff --git a/test1.txt b/test1.txt new file mode 100644 index 0000000..5852f44 --- /dev/null +++ b/test1.txt @@ -0,0 +1 @@ +Initial commit From c9504e30162c7c9edb0d224dc0b00d08d8015fdb Mon Sep 17 00:00:00 2001 From: Saravanan Date: Sun, 6 Oct 2024 03:40:06 +0100 Subject: [PATCH 6/6] Issue Fix --- src/com/.DS_Store | Bin 6148 -> 6148 bytes src/com/array/rotations/ArrayAverage.java | 29 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/com/array/rotations/ArrayAverage.java diff --git a/src/com/.DS_Store b/src/com/.DS_Store index e3f6b962a8d3e515daac87e75f107ef2a74fcc0d..e716a71c54610e9cbd7939b956cfee9e42bcdd01 100644 GIT binary patch delta 96 zcmZoMXfc=|#>B`mu~2NHo}w@d0|Nsi1A_nqLuF37VQ_MOZo$ODm5eNt=dd(SE@z*x rS%HI{Wn;rb#?9;;{2V}in*}+(Gf(Chu>@)XYh{AcESn=l)-VGAYyA~C literal 6148 zcmeHLv2GJV5S9MNA*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( diff --git a/src/com/array/rotations/ArrayAverage.java b/src/com/array/rotations/ArrayAverage.java new file mode 100644 index 0000000..fd362c5 --- /dev/null +++ b/src/com/array/rotations/ArrayAverage.java @@ -0,0 +1,29 @@ +package com.array.rotations; + +public class ArrayAverage { + + public static void main(String[] args) { + int n = 10; + int[] arr = new int[n]; + + // Input array elements + System.out.println("Enter the elements of the array: "); + for (int i = 0; i < n; i++) { + arr[i] = 1+i; + } + + // Calculate sum of elements + int sum = 0; + for (int i = 0; i < n; i++) { + sum += arr[i]; + } + + // Calculate average + double average = (double) sum / n; + + // Output the average + System.out.println("The average is: " + average); + + } + +}