From 40620aea1b728c9a8fd1f931ec503660dd06e8c9 Mon Sep 17 00:00:00 2001 From: joshiujjawal22 Date: Mon, 18 May 2020 23:24:57 +0530 Subject: [PATCH 1/3] To find sum of triplets according to given value --- Others/3 sum.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Others/3 sum.java diff --git a/Others/3 sum.java b/Others/3 sum.java new file mode 100644 index 000000000..3c008ff78 --- /dev/null +++ b/Others/3 sum.java @@ -0,0 +1,48 @@ +package Others; + +import java.util.Scanner; +import java.util.Arrays; + +/** + * To find triplet equals to given sum in complexity O(n*log(n)) + * + * + * Array must be sorted + * + * @author Ujjawal Joshi + * @date 2020.05.18 + */ + + +class threesum{ + public static void main(String args[]) + { + Scanner sc =new Scanner(System.in); + int n=sc.nextInt(); //Length of an array + + int a[]=new int[n]; + + for(int i=0;i Date: Mon, 18 May 2020 23:35:06 +0530 Subject: [PATCH 2/3] Rotation of an array without using extra space --- ...on of array without using extra space.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Others/Rotation of array without using extra space.java diff --git a/Others/Rotation of array without using extra space.java b/Others/Rotation of array without using extra space.java new file mode 100644 index 000000000..c25dbaefc --- /dev/null +++ b/Others/Rotation of array without using extra space.java @@ -0,0 +1,54 @@ +package Others; + +import java.util.*; + +/** + * Rotation of array without using extra space + * + * + * @author Ujjawal Joshi + * @date 2020.05.18 + */ + +class main{ + public static void main(String[] args) + { + Scanner sc=new Scanner(System.in); + int n=sc.nextInt(); + int a[][]=new int[n][n]; + + for(int i=0;i Date: Fri, 29 May 2020 12:32:24 +0530 Subject: [PATCH 3/3] Added test cases --- Others/3 sum.java | 14 ++++++++++++- ...on of array without using extra space.java | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Others/3 sum.java b/Others/3 sum.java index 3c008ff78..577044aab 100644 --- a/Others/3 sum.java +++ b/Others/3 sum.java @@ -11,6 +11,18 @@ import java.util.Arrays; * * @author Ujjawal Joshi * @date 2020.05.18 + * + * Test Cases: + Input: + * 6 //Length of array + 12 3 4 1 6 9 + target=24 + * Output:3 9 12 + * Explanation: There is a triplet (12, 3 and 9) present + in the array whose sum is 24. + * + * + */ @@ -26,7 +38,7 @@ class threesum{ { a[i]=sc.nextInt(); } - System.out.println("Number to be find"); + System.out.println("Target"); int n_find=sc.nextInt(); Arrays.sort(a); // Sort the array if array is not sorted diff --git a/Others/Rotation of array without using extra space.java b/Others/Rotation of array without using extra space.java index c25dbaefc..76380be37 100644 --- a/Others/Rotation of array without using extra space.java +++ b/Others/Rotation of array without using extra space.java @@ -8,6 +8,27 @@ import java.util.*; * * @author Ujjawal Joshi * @date 2020.05.18 + * + * Test Cases: + + Input: + 2 //Size of matrix + 1 2 + 3 4 + Output: + 3 1 + 4 2 + ------------------------------ + Input: + 3 //Size of matrix + 1 2 3 + 4 5 6 + 7 8 9 + Output: + 7 4 1 + 8 5 2 + 9 6 3 + * */ class main{