From b5ed6ba70ed9a9c695f1c222bb1f26c679297ab8 Mon Sep 17 00:00:00 2001 From: Rishiraj <52316252+Rishiraj122@users.noreply.github.com> Date: Fri, 2 Oct 2020 12:28:16 +0530 Subject: [PATCH 1/4] Added Longest Pallindromic Subsequence in Java --- LongestPallindromicSubsequenc.java | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LongestPallindromicSubsequenc.java diff --git a/LongestPallindromicSubsequenc.java b/LongestPallindromicSubsequenc.java new file mode 100644 index 0000000..00dc870 --- /dev/null +++ b/LongestPallindromicSubsequenc.java @@ -0,0 +1,55 @@ +import java.util.*; +import java.lang.*; +import java.io.*; + +class LongestPallindromicSubsequenc{ + + int max(int a, int b) + { + return (a>b ? a:b); + } + + int LCS(int n, char[] arr, char[] b){ + + int[][] dp=new int[n+1][n+1]; + + for(int i=0;i0){ + String str=sc.next(); + int n=str.length(); + char[] arr=str.toCharArray(); + char[] b=new char[n]; + + for(int i=0;i Date: Fri, 2 Oct 2020 12:54:45 +0530 Subject: [PATCH 2/4] Added Dynamic Programming Folder and added the LPS algo in it --- .../LongestPallindromicSubsequenc.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Dynamic Programming/LongestPallindromicSubsequenc.java diff --git a/Dynamic Programming/LongestPallindromicSubsequenc.java b/Dynamic Programming/LongestPallindromicSubsequenc.java new file mode 100644 index 0000000..00dc870 --- /dev/null +++ b/Dynamic Programming/LongestPallindromicSubsequenc.java @@ -0,0 +1,55 @@ +import java.util.*; +import java.lang.*; +import java.io.*; + +class LongestPallindromicSubsequenc{ + + int max(int a, int b) + { + return (a>b ? a:b); + } + + int LCS(int n, char[] arr, char[] b){ + + int[][] dp=new int[n+1][n+1]; + + for(int i=0;i0){ + String str=sc.next(); + int n=str.length(); + char[] arr=str.toCharArray(); + char[] b=new char[n]; + + for(int i=0;i Date: Fri, 2 Oct 2020 13:08:00 +0530 Subject: [PATCH 3/4] Changes in folders --- Anagram.java => Algorithms/Anagram.java | 0 Factorial.java => Algorithms/Factorial.java | 0 Gcd.java => Algorithms/Gcd.java | 0 .../PascalTriangle.java | 0 ...Pattern Search Algorithm( Naive algorithm) | 0 .../PrimsAlgorithm.java | 0 .../SeiveOfEratosthenes.java | 0 .../SubsetsOfArray.java | 0 .../SuffixArray.java | 0 .../recursiveBinarysearch.java | 58 +-- BinarySearch.java | 33 -- Bubble.java | 27 -- .../LongestPallindromicSubsequenc.java | 55 --- Graph Algorithms/Graph.java | 91 ----- {BFS => Graph/BFS}/BFS.java | 0 BFSgraph.java => Graph/BFSgraph.java | 0 {Graph Algorithms => Graph}/Cyclic_detection | 0 {DFS => Graph/DFS}/DFS.java | 0 DFSgraph.java => Graph/DFSgraph.java | 0 {Graph Algorithms => Graph}/Description | 0 Graph.java => Graph/Graph.java | 0 .../Single_source_Shortest Path | 0 {Graph Algorithms => Graph}/k_cores.java | 340 +++++++++--------- Insertion.java | 24 -- Interview Questions/Questions.md | 12 + LongestPallindromicSubsequenc.java | 55 --- Queue.java => Queue/Queue.java | 0 Selection.java | 28 -- BubbleSort.java => Sorting/BubbleSort.java | 0 .../CocktailSort.java | 0 .../Frequency_Sort.java | 0 .../InsertionSort.java | 0 .../Randomized_Quick_Sort.java | 0 .../selectionSort.java | 0 AVLtree.java => Tree/AVLtree.java | 0 BFSTree.java => Tree/BFSTree.java | 0 .../Second_Minimum_In_Binary_Tree.java | 0 .../binarySearchTree}/Bst.java | 0 .../binarySearchTree}/TreeNode.java | 0 39 files changed, 211 insertions(+), 512 deletions(-) rename Anagram.java => Algorithms/Anagram.java (100%) rename Factorial.java => Algorithms/Factorial.java (100%) rename Gcd.java => Algorithms/Gcd.java (100%) rename PascalTriangle.java => Algorithms/PascalTriangle.java (100%) rename Pattern Search Algorithm( Naive algorithm) => Algorithms/Pattern Search Algorithm( Naive algorithm) (100%) rename PrimsAlgorithm.java => Algorithms/PrimsAlgorithm.java (100%) rename SeiveOfEratosthenes.java => Algorithms/SeiveOfEratosthenes.java (100%) rename SubsetsOfArray.java => Algorithms/SubsetsOfArray.java (100%) rename SuffixArray.java => Algorithms/SuffixArray.java (100%) rename recursiveBinarysearch.java => Algorithms/recursiveBinarysearch.java (96%) delete mode 100644 BinarySearch.java delete mode 100644 Bubble.java delete mode 100644 Dynamic Programming/LongestPallindromicSubsequenc.java delete mode 100644 Graph Algorithms/Graph.java rename {BFS => Graph/BFS}/BFS.java (100%) rename BFSgraph.java => Graph/BFSgraph.java (100%) rename {Graph Algorithms => Graph}/Cyclic_detection (100%) rename {DFS => Graph/DFS}/DFS.java (100%) rename DFSgraph.java => Graph/DFSgraph.java (100%) rename {Graph Algorithms => Graph}/Description (100%) rename Graph.java => Graph/Graph.java (100%) rename {Graph Algorithms => Graph}/Single_source_Shortest Path (100%) rename {Graph Algorithms => Graph}/k_cores.java (95%) delete mode 100644 Insertion.java create mode 100644 Interview Questions/Questions.md delete mode 100644 LongestPallindromicSubsequenc.java rename Queue.java => Queue/Queue.java (100%) delete mode 100644 Selection.java rename BubbleSort.java => Sorting/BubbleSort.java (100%) rename CocktailSort.java => Sorting/CocktailSort.java (100%) rename Frequency_Sort.java => Sorting/Frequency_Sort.java (100%) rename InsertionSort.java => Sorting/InsertionSort.java (100%) rename Randomized_Quick_Sort.java => Sorting/Randomized_Quick_Sort.java (100%) rename selectionSort.java => Sorting/selectionSort.java (100%) rename AVLtree.java => Tree/AVLtree.java (100%) rename BFSTree.java => Tree/BFSTree.java (100%) rename Second_Minimum_In_Binary_Tree.java => Tree/Second_Minimum_In_Binary_Tree.java (100%) rename {binarySearchTree => Tree/binarySearchTree}/Bst.java (100%) rename {binarySearchTree => Tree/binarySearchTree}/TreeNode.java (100%) diff --git a/Anagram.java b/Algorithms/Anagram.java similarity index 100% rename from Anagram.java rename to Algorithms/Anagram.java diff --git a/Factorial.java b/Algorithms/Factorial.java similarity index 100% rename from Factorial.java rename to Algorithms/Factorial.java diff --git a/Gcd.java b/Algorithms/Gcd.java similarity index 100% rename from Gcd.java rename to Algorithms/Gcd.java diff --git a/PascalTriangle.java b/Algorithms/PascalTriangle.java similarity index 100% rename from PascalTriangle.java rename to Algorithms/PascalTriangle.java diff --git a/Pattern Search Algorithm( Naive algorithm) b/Algorithms/Pattern Search Algorithm( Naive algorithm) similarity index 100% rename from Pattern Search Algorithm( Naive algorithm) rename to Algorithms/Pattern Search Algorithm( Naive algorithm) diff --git a/PrimsAlgorithm.java b/Algorithms/PrimsAlgorithm.java similarity index 100% rename from PrimsAlgorithm.java rename to Algorithms/PrimsAlgorithm.java diff --git a/SeiveOfEratosthenes.java b/Algorithms/SeiveOfEratosthenes.java similarity index 100% rename from SeiveOfEratosthenes.java rename to Algorithms/SeiveOfEratosthenes.java diff --git a/SubsetsOfArray.java b/Algorithms/SubsetsOfArray.java similarity index 100% rename from SubsetsOfArray.java rename to Algorithms/SubsetsOfArray.java diff --git a/SuffixArray.java b/Algorithms/SuffixArray.java similarity index 100% rename from SuffixArray.java rename to Algorithms/SuffixArray.java diff --git a/recursiveBinarysearch.java b/Algorithms/recursiveBinarysearch.java similarity index 96% rename from recursiveBinarysearch.java rename to Algorithms/recursiveBinarysearch.java index 694726d..2c007e1 100644 --- a/recursiveBinarysearch.java +++ b/Algorithms/recursiveBinarysearch.java @@ -1,29 +1,29 @@ -package Searching; -import Sorting.Selection; -import java.util.Scanner; - -public class recursiveBinarysearch { -static Scanner sc=new Scanner(System.in); - public static int search(int array[],int key,int li,int ui) { - int curindex=(li+ui)/2; - if(li>ui)return -1; - if(array[curindex]==key)return key; - else if(key>array[curindex])return search(array,key,curindex+1,ui); - else - return search(array,key,li,curindex-1); - } - public static void main(String[] args) { - // TODO Auto-generated method stub - int n=sc.nextInt(); - int array[]=new int[n]; - for(int i=0;iui)return -1; + if(array[curindex]==key)return key; + else if(key>array[curindex])return search(array,key,curindex+1,ui); + else + return search(array,key,li,curindex-1); + } + public static void main(String[] args) { + // TODO Auto-generated method stub + int n=sc.nextInt(); + int array[]=new int[n]; + for(int i=0;iui)break; - else if(search>array[curin]) - li=curin+1; - else - ui=curin-1; - } - if(found)System.out.println("Yes"); - else - System.out.println("No"); - } - -} diff --git a/Bubble.java b/Bubble.java deleted file mode 100644 index c8827f0..0000000 --- a/Bubble.java +++ /dev/null @@ -1,27 +0,0 @@ -package Sorting; -import java.util.Scanner; -public class Bubble { -static Scanner sc=new Scanner(System.in); - void sort(int array[]) { - int n=array.length; - for(int i=n-1;i>1;i--) { - for(int j=0;jarray[j+1]) { - int temp=array[j]; - array[j]=array[j+1]; - array[j+1]=temp; - } - } - } - } - public static void main(String[] args) { - // TODO Auto-generated method stub - int n=sc.nextInt(); - int[] array=new int[n]; - for(int i=0;ib ? a:b); - } - - int LCS(int n, char[] arr, char[] b){ - - int[][] dp=new int[n+1][n+1]; - - for(int i=0;i0){ - String str=sc.next(); - int n=str.length(); - char[] arr=str.toCharArray(); - char[] b=new char[n]; - - for(int i=0;i adj[]; - - @SuppressWarnings("unchecked") - Graph(int v) - { - V = v; - adj = new LinkedList[v]; - for (int i = 0; i < v; ++i) - adj[i] = new LinkedList<>(); - } - - // Method to add an edge into the graph - void addEdge(int v, int w) - { - - // Add w to v's list. - adj[v].add(w); - } - - // A recursive method to count - // all paths from 'u' to 'd'. - int countPathsUtil(int u, int d, - int pathCount) - { - - // If current vertex is same as - // destination, then increment count - if (u == d) { - pathCount++; - } - - // Recur for all the vertices - // adjacent to this vertex - else { - Iterator i = adj[u].listIterator(); - while (i.hasNext()) { - int n = i.next(); - pathCount = countPathsUtil(n, d, pathCount); - } - } - return pathCount; - } - - // Returns count of - // paths from 's' to 'd' - int countPaths(int s, int d) - { - - // Call the recursive method - // to count all paths - int pathCount = 0; - pathCount = countPathsUtil(s, d, - pathCount); - return pathCount; - } - - // Driver Code - public static void main(String args[]) - { - Graph g = new Graph(5); - g.addEdge(0, 1); - g.addEdge(0, 2); - g.addEdge(0, 3); - g.addEdge(1, 3); - g.addEdge(2, 3); - g.addEdge(1, 4); - g.addEdge(2, 4); - - int s = 0, d = 3; - System.out.println(g.countPaths(s, d)); - } -} - - diff --git a/BFS/BFS.java b/Graph/BFS/BFS.java similarity index 100% rename from BFS/BFS.java rename to Graph/BFS/BFS.java diff --git a/BFSgraph.java b/Graph/BFSgraph.java similarity index 100% rename from BFSgraph.java rename to Graph/BFSgraph.java diff --git a/Graph Algorithms/Cyclic_detection b/Graph/Cyclic_detection similarity index 100% rename from Graph Algorithms/Cyclic_detection rename to Graph/Cyclic_detection diff --git a/DFS/DFS.java b/Graph/DFS/DFS.java similarity index 100% rename from DFS/DFS.java rename to Graph/DFS/DFS.java diff --git a/DFSgraph.java b/Graph/DFSgraph.java similarity index 100% rename from DFSgraph.java rename to Graph/DFSgraph.java diff --git a/Graph Algorithms/Description b/Graph/Description similarity index 100% rename from Graph Algorithms/Description rename to Graph/Description diff --git a/Graph.java b/Graph/Graph.java similarity index 100% rename from Graph.java rename to Graph/Graph.java diff --git a/Graph Algorithms/Single_source_Shortest Path b/Graph/Single_source_Shortest Path similarity index 100% rename from Graph Algorithms/Single_source_Shortest Path rename to Graph/Single_source_Shortest Path diff --git a/Graph Algorithms/k_cores.java b/Graph/k_cores.java similarity index 95% rename from Graph Algorithms/k_cores.java rename to Graph/k_cores.java index eecba82..314b08d 100644 --- a/Graph Algorithms/k_cores.java +++ b/Graph/k_cores.java @@ -1,170 +1,170 @@ -// Java program to find K-Cores of a graph -import java.util.*; - -class k_cores -{ - - // This class represents a undirected graph using adjacency - // list representation - static class Graph - { - int V; // No. of vertices - - // Pointer to an array containing adjacency lists - Vector[] adj; - - @SuppressWarnings("unchecked") - Graph(int V) - { - this.V = V; - this.adj = new Vector[V]; - - for (int i = 0; i < V; i++) - adj[i] = new Vector<>(); - } - - // function to add an edge to graph - void addEdge(int u, int v) - { - this.adj[u].add(v); - this.adj[v].add(u); - } - - // A recursive function to print DFS starting from v. - // It returns true if degree of v after processing is less - // than k else false - // It also updates degree of adjacent if degree of v - // is less than k. And if degree of a processed adjacent - // becomes less than k, then it reduces of degree of v also, - boolean DFSUtil(int v, boolean[] visited, int[] vDegree, int k) - { - - // Mark the current node as visited and print it - visited[v] = true; - - // Recur for all the vertices adjacent to this vertex - for (int i : adj[v]) - { - - // degree of v is less than k, then degree of adjacent - // must be reduced - if (vDegree[v] < k) - vDegree[i]--; - - // If adjacent is not processed, process it - if (!visited[i]) - { - - // If degree of adjacent after processing becomes - // less than k, then reduce degree of v also. - if (DFSUtil(i, visited, vDegree, k)) - vDegree[v]--; - } - } - - // Return true if degree of v is less than k - return (vDegree[v] < k); - } - - // Prints k cores of an undirected graph - void printKCores(int k) - { - - // INITIALIZATION - // Mark all the vertices as not visited and not - // processed. - boolean[] visited = new boolean[V]; - boolean[] processed = new boolean[V]; - Arrays.fill(visited, false); - Arrays.fill(processed, false); - - int mindeg = Integer.MAX_VALUE; - int startvertex = 0; - - // Store degrees of all vertices - int[] vDegree = new int[V]; - for (int i = 0; i < V; i++) - { - vDegree[i] = adj[i].size(); - - if (vDegree[i] < mindeg) - { - mindeg = vDegree[i]; - startvertex = i; - } - } - DFSUtil(startvertex, visited, vDegree, k); - - // DFS traversal to update degrees of all - // vertices. - for (int i = 0; i < V; i++) - if (!visited[i]) - DFSUtil(i, visited, vDegree, k); - - // PRINTING K CORES - System.out.println("K-Cores : "); - for (int v = 0; v < V; v++) - { - - // Only considering those vertices which have degree - // >= K after BFS - if (vDegree[v] >= k) - { - System.out.printf("\n[%d]", v); - - // Traverse adjacency list of v and print only - // those adjacent which have vDegree >= k after - // BFS. - for (int i : adj[v]) - if (vDegree[i] >= k) - System.out.printf(" -> %d", i); - } - } - } - } - - // Driver Code - public static void main(String[] args) - { - - // Create a graph given in the above diagram - int k = 3; - Graph g1 = new Graph(9); - g1.addEdge(0, 1); - g1.addEdge(0, 2); - g1.addEdge(1, 2); - g1.addEdge(1, 5); - g1.addEdge(2, 3); - g1.addEdge(2, 4); - g1.addEdge(2, 5); - g1.addEdge(2, 6); - g1.addEdge(3, 4); - g1.addEdge(3, 6); - g1.addEdge(3, 7); - g1.addEdge(4, 6); - g1.addEdge(4, 7); - g1.addEdge(5, 6); - g1.addEdge(5, 8); - g1.addEdge(6, 7); - g1.addEdge(6, 8); - g1.printKCores(k); - - System.out.println(); - - Graph g2 = new Graph(13); - g2.addEdge(0, 1); - g2.addEdge(0, 2); - g2.addEdge(0, 3); - g2.addEdge(1, 4); - g2.addEdge(1, 5); - g2.addEdge(1, 6); - g2.addEdge(2, 7); - g2.addEdge(2, 8); - g2.addEdge(2, 9); - g2.addEdge(3, 10); - g2.addEdge(3, 11); - g2.addEdge(3, 12); - g2.printKCores(k); - } -} - +// Java program to find K-Cores of a graph +import java.util.*; + +class k_cores +{ + + // This class represents a undirected graph using adjacency + // list representation + static class Graph + { + int V; // No. of vertices + + // Pointer to an array containing adjacency lists + Vector[] adj; + + @SuppressWarnings("unchecked") + Graph(int V) + { + this.V = V; + this.adj = new Vector[V]; + + for (int i = 0; i < V; i++) + adj[i] = new Vector<>(); + } + + // function to add an edge to graph + void addEdge(int u, int v) + { + this.adj[u].add(v); + this.adj[v].add(u); + } + + // A recursive function to print DFS starting from v. + // It returns true if degree of v after processing is less + // than k else false + // It also updates degree of adjacent if degree of v + // is less than k. And if degree of a processed adjacent + // becomes less than k, then it reduces of degree of v also, + boolean DFSUtil(int v, boolean[] visited, int[] vDegree, int k) + { + + // Mark the current node as visited and print it + visited[v] = true; + + // Recur for all the vertices adjacent to this vertex + for (int i : adj[v]) + { + + // degree of v is less than k, then degree of adjacent + // must be reduced + if (vDegree[v] < k) + vDegree[i]--; + + // If adjacent is not processed, process it + if (!visited[i]) + { + + // If degree of adjacent after processing becomes + // less than k, then reduce degree of v also. + if (DFSUtil(i, visited, vDegree, k)) + vDegree[v]--; + } + } + + // Return true if degree of v is less than k + return (vDegree[v] < k); + } + + // Prints k cores of an undirected graph + void printKCores(int k) + { + + // INITIALIZATION + // Mark all the vertices as not visited and not + // processed. + boolean[] visited = new boolean[V]; + boolean[] processed = new boolean[V]; + Arrays.fill(visited, false); + Arrays.fill(processed, false); + + int mindeg = Integer.MAX_VALUE; + int startvertex = 0; + + // Store degrees of all vertices + int[] vDegree = new int[V]; + for (int i = 0; i < V; i++) + { + vDegree[i] = adj[i].size(); + + if (vDegree[i] < mindeg) + { + mindeg = vDegree[i]; + startvertex = i; + } + } + DFSUtil(startvertex, visited, vDegree, k); + + // DFS traversal to update degrees of all + // vertices. + for (int i = 0; i < V; i++) + if (!visited[i]) + DFSUtil(i, visited, vDegree, k); + + // PRINTING K CORES + System.out.println("K-Cores : "); + for (int v = 0; v < V; v++) + { + + // Only considering those vertices which have degree + // >= K after BFS + if (vDegree[v] >= k) + { + System.out.printf("\n[%d]", v); + + // Traverse adjacency list of v and print only + // those adjacent which have vDegree >= k after + // BFS. + for (int i : adj[v]) + if (vDegree[i] >= k) + System.out.printf(" -> %d", i); + } + } + } + } + + // Driver Code + public static void main(String[] args) + { + + // Create a graph given in the above diagram + int k = 3; + Graph g1 = new Graph(9); + g1.addEdge(0, 1); + g1.addEdge(0, 2); + g1.addEdge(1, 2); + g1.addEdge(1, 5); + g1.addEdge(2, 3); + g1.addEdge(2, 4); + g1.addEdge(2, 5); + g1.addEdge(2, 6); + g1.addEdge(3, 4); + g1.addEdge(3, 6); + g1.addEdge(3, 7); + g1.addEdge(4, 6); + g1.addEdge(4, 7); + g1.addEdge(5, 6); + g1.addEdge(5, 8); + g1.addEdge(6, 7); + g1.addEdge(6, 8); + g1.printKCores(k); + + System.out.println(); + + Graph g2 = new Graph(13); + g2.addEdge(0, 1); + g2.addEdge(0, 2); + g2.addEdge(0, 3); + g2.addEdge(1, 4); + g2.addEdge(1, 5); + g2.addEdge(1, 6); + g2.addEdge(2, 7); + g2.addEdge(2, 8); + g2.addEdge(2, 9); + g2.addEdge(3, 10); + g2.addEdge(3, 11); + g2.addEdge(3, 12); + g2.printKCores(k); + } +} + diff --git a/Insertion.java b/Insertion.java deleted file mode 100644 index 6a4752a..0000000 --- a/Insertion.java +++ /dev/null @@ -1,24 +0,0 @@ -package Sorting; - -import java.util.Scanner; - -public class Insertion { - static Scanner sc=new Scanner(System.in); - public static void sort(int [] array) { - int n=array.length,j; - for(int i=1;i=0 && temp main() in Java is the entry point for any Java program. It is always written as public static void main(String[] args). + * public: Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class. + * static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a Class. In case, main is not made static then the compiler will throw an error as main() is called by the JVM before any objects are made and only static methods can be directly invoked via the class. + * void: It is the return type of the method. Void defines the method which will not return any value. + * main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs. + * String args[]: It is the parameter passed to the main method. \ No newline at end of file diff --git a/LongestPallindromicSubsequenc.java b/LongestPallindromicSubsequenc.java deleted file mode 100644 index 00dc870..0000000 --- a/LongestPallindromicSubsequenc.java +++ /dev/null @@ -1,55 +0,0 @@ -import java.util.*; -import java.lang.*; -import java.io.*; - -class LongestPallindromicSubsequenc{ - - int max(int a, int b) - { - return (a>b ? a:b); - } - - int LCS(int n, char[] arr, char[] b){ - - int[][] dp=new int[n+1][n+1]; - - for(int i=0;i0){ - String str=sc.next(); - int n=str.length(); - char[] arr=str.toCharArray(); - char[] b=new char[n]; - - for(int i=0;i Date: Fri, 2 Oct 2020 13:09:24 +0530 Subject: [PATCH 4/4] Added Longest Palliandromic Subsequence --- Algorithms/LongestPallindromicSubsequenc.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Algorithms/LongestPallindromicSubsequenc.java diff --git a/Algorithms/LongestPallindromicSubsequenc.java b/Algorithms/LongestPallindromicSubsequenc.java new file mode 100644 index 0000000..00dc870 --- /dev/null +++ b/Algorithms/LongestPallindromicSubsequenc.java @@ -0,0 +1,55 @@ +import java.util.*; +import java.lang.*; +import java.io.*; + +class LongestPallindromicSubsequenc{ + + int max(int a, int b) + { + return (a>b ? a:b); + } + + int LCS(int n, char[] arr, char[] b){ + + int[][] dp=new int[n+1][n+1]; + + for(int i=0;i0){ + String str=sc.next(); + int n=str.length(); + char[] arr=str.toCharArray(); + char[] b=new char[n]; + + for(int i=0;i