diff --git a/BinarySearch.java b/BinarySearch.java new file mode 100644 index 0000000..8f04111 --- /dev/null +++ b/BinarySearch.java @@ -0,0 +1,54 @@ +// { Driver Code Starts +//Initial Template for Java + +import java.io.*; +import java.util.*; + +public class GFG { + public static void main (String[] args) throws IOException { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + while(T>0) + { + int n = sc.nextInt(); + int arr[] = new int[n]; + for(int i=0;i0) + { + int N = sc.nextInt(); + Solution ob = new Solution(); + ArrayList ans = ob.factorial(N); + for (Integer val: ans) + System.out.print(val); + System.out.println(); + } + } +}// } Driver Code Ends + + +//User function Template for Java + +class Solution { + static ArrayList factorial(int N){ + //code here + ArrayList a=new ArrayList<>(); + a.add(1); + int i,; + for(i=2;i<=N;i++){ + mul(i,a); + } + //System.out.println(a); + Collections.reverse(a); + return a; + } + static void mul(int x, ArrayList l){ + int i, prod,carry=0; + + for(i=0;i 2->3->4->5, then the middle node of the list is 3. +// If there are two middle nodes(in case, when N is even), print the second middle element. +// For example, if the linked list given is 1->2->3->4->5->6, then the middle node of the list is 4. + + + +import java.util.*; +import java.io.*; + +class Node{ + int data; + Node next; + + Node(int x){ + data = x; + next = null; + } + +} +class Middle{ + static void printList(Node node) + { + while (node != null) + { + System.out.print(node.data + " "); + node = node.next; + } + System.out.println(); + } + public static void main(String args[]) throws IOException { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + while(t > 0){ + int n = sc.nextInt(); + Node head = new Node(sc.nextInt()); + Node tail = head; + for(int i=0; i