From 4cc268ce66ecf0836952add169528a21361b091e Mon Sep 17 00:00:00 2001 From: Nellius Kyalo Date: Wed, 1 Dec 2021 08:57:34 +0300 Subject: [PATCH 1/6] Final submission --- .../Arrays and Strings/ReverseArray.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Nelliuslinda/Arrays and Strings/ReverseArray.java diff --git a/Nelliuslinda/Arrays and Strings/ReverseArray.java b/Nelliuslinda/Arrays and Strings/ReverseArray.java new file mode 100644 index 0000000..e5b80a3 --- /dev/null +++ b/Nelliuslinda/Arrays and Strings/ReverseArray.java @@ -0,0 +1,24 @@ +package com.company; + +public class Main { + //Function to reverse Array + static void reverseArray(int[] arr){ + int x = arr.length; + for (int i=0; i< arr.length/2; i++){ + int temp = arr[i]; + arr[i]=arr[x-1-i]; + arr[x-1-i]=temp; + } + for (int j : arr) { + System.out.println(j); + } + + } + + //Driver function to reverse Array + public static void main(String[] args) { + int[] A = new int[]{10,5,6,9}; + System.out.println("The new reversed array is:"); + reverseArray(A); + } +} From 716ce73e188504da16cbc6164d7effff134071da Mon Sep 17 00:00:00 2001 From: Nellius Kyalo Date: Tue, 25 Jan 2022 16:27:24 +0300 Subject: [PATCH 2/6] Between Two Sets Solution --- .../BetweenTwoSets-HackerRank.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java diff --git a/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java b/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java new file mode 100644 index 0000000..6af954b --- /dev/null +++ b/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java @@ -0,0 +1,58 @@ +package com.company; + +import java.util.Arrays; +import java.util.List; + +public class Main { + //Function to find GCD + static int findGCD(int n1, int n2) { + if (n2 == 0) { + return n1; + } + return findGCD(n2, n1 % n2); + } + + //Function to find LCM + static int findLCM(int n1, int n2) { + if (n1 == 0 || n2 == 0) + return 0; + else { + int gcd = findGCD(n1, n2); + return Math.abs(n1 * n2) / gcd; + } + } + + public static int getTotalX(List a, List b) { + int result = 0; + + // Call LCM function to get lcm of array a + int lcm = a.get(0); + for (Integer integer : a) { + lcm = findLCM(lcm, integer); + } + + // Call GCD function to find gcd of array b + int gcd = b.get(0); + for (Integer integer : b) { + gcd = findGCD(gcd, integer); + } + + // Find common multiple of LCM that can divide GCD + int cm = 0; + while (cm <= gcd) { + cm += lcm; + + if (gcd % cm == 0) + result++; + } + + return result; + } + public static void main(String[] args) { + + Lista = Arrays.asList(2,4); + Listb = Arrays.asList(16,32,96); + + System.out.println(getTotalX(a,b)); + } +} From ac279b784cbba047f7b4e4b40b0e4d9a6c7690bb Mon Sep 17 00:00:00 2001 From: Linda Kyalo <60879301+Nelliuslinda@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:33:51 +0300 Subject: [PATCH 3/6] Delete BetweenTwoSets-HackerRank.java --- .../BetweenTwoSets-HackerRank.java | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java diff --git a/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java b/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java deleted file mode 100644 index 6af954b..0000000 --- a/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.company; - -import java.util.Arrays; -import java.util.List; - -public class Main { - //Function to find GCD - static int findGCD(int n1, int n2) { - if (n2 == 0) { - return n1; - } - return findGCD(n2, n1 % n2); - } - - //Function to find LCM - static int findLCM(int n1, int n2) { - if (n1 == 0 || n2 == 0) - return 0; - else { - int gcd = findGCD(n1, n2); - return Math.abs(n1 * n2) / gcd; - } - } - - public static int getTotalX(List a, List b) { - int result = 0; - - // Call LCM function to get lcm of array a - int lcm = a.get(0); - for (Integer integer : a) { - lcm = findLCM(lcm, integer); - } - - // Call GCD function to find gcd of array b - int gcd = b.get(0); - for (Integer integer : b) { - gcd = findGCD(gcd, integer); - } - - // Find common multiple of LCM that can divide GCD - int cm = 0; - while (cm <= gcd) { - cm += lcm; - - if (gcd % cm == 0) - result++; - } - - return result; - } - public static void main(String[] args) { - - Lista = Arrays.asList(2,4); - Listb = Arrays.asList(16,32,96); - - System.out.println(getTotalX(a,b)); - } -} From 88c75e0fc055fa1eb9345bd82bbb55f8a5433317 Mon Sep 17 00:00:00 2001 From: Linda Kyalo <60879301+Nelliuslinda@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:39:04 +0300 Subject: [PATCH 4/6] Create BetweenTwoSets.java --- Nelliuslinda/Big O Notation/BetweenTwoSets.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 Nelliuslinda/Big O Notation/BetweenTwoSets.java diff --git a/Nelliuslinda/Big O Notation/BetweenTwoSets.java b/Nelliuslinda/Big O Notation/BetweenTwoSets.java new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Nelliuslinda/Big O Notation/BetweenTwoSets.java @@ -0,0 +1 @@ + From 21c740578d44fac9448e716ba60bfc9a9317f25d Mon Sep 17 00:00:00 2001 From: Linda Kyalo <60879301+Nelliuslinda@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:40:00 +0300 Subject: [PATCH 5/6] Between Two Sets Solution --- .../BetweenTwoSets-HackerRank.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java diff --git a/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java b/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java new file mode 100644 index 0000000..3cee16c --- /dev/null +++ b/Nelliuslinda/Big O Notation/BetweenTwoSets-HackerRank.java @@ -0,0 +1,58 @@ +package com.company; + +import java.util.Arrays; +import java.util.List; + +public class Main { + //Function to find GCD + static int findGCD(int n1, int n2) { + if (n2 == 0) { + return n1; + } + return findGCD(n2, n1 % n2); + } + + //Function to find LCM + static int findLCM(int n1, int n2) { + if (n1 == 0 || n2 == 0) + return 0; + else { + int gcd = findGCD(n1, n2); + return Math.abs(n1 * n2) / gcd; + } + } + + public static int getTotalX(List a, List b) { + int result = 0; + + // Call LCM function to get lcm of array a + int lcm = a.get(0); + for (Integer integer : a) { + lcm = findLCM(lcm, integer); + } + + // Call GCD function to find gcd of array b + int gcd = b.get(0); + for (Integer integer : b) { + gcd = findGCD(gcd, integer); + } + + // Find common multiple of LCM that can divide GCD + int cm = 0; + while (cm <= gcd) { + cm += lcm; + + if (gcd % cm == 0) + result++; + } + + return result; + } + public static void main(String[] args) { + + Lista = Arrays.asList(2,4); + Listb = Arrays.asList(16,32,96); + + System.out.println(getTotalX(a,b)); + } +} From 739e2c169856957ab298fa8ddb31d4775a0b865c Mon Sep 17 00:00:00 2001 From: Linda Kyalo <60879301+Nelliuslinda@users.noreply.github.com> Date: Tue, 25 Jan 2022 16:41:14 +0300 Subject: [PATCH 6/6] Delete BetweenTwoSets.java --- Nelliuslinda/Big O Notation/BetweenTwoSets.java | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Nelliuslinda/Big O Notation/BetweenTwoSets.java diff --git a/Nelliuslinda/Big O Notation/BetweenTwoSets.java b/Nelliuslinda/Big O Notation/BetweenTwoSets.java deleted file mode 100644 index 8b13789..0000000 --- a/Nelliuslinda/Big O Notation/BetweenTwoSets.java +++ /dev/null @@ -1 +0,0 @@ -