├── BinarySearch.java ├── ClaimStairsDP.java ├── CountingBits.java ├── DPP.png ├── DesignALinkedList.java ├── Leetcode.java ├── LinkedListpalindrome.java ├── Memoization.java ├── Time_Teller.java ├── designAStack.java ├── hello.java ├── reverseANuumberUsingStack.java └── springboot.java /BinarySearch.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int[] arr={1,23,41,42,44,66,777,888,999}; 6 | int ans=BinarySearch(arr,888,0,8); 7 | System.out.println("Element founded at index :"+ans); 8 | } 9 | public static int BinarySearch(int[] ar,int key,int start,int end){ 10 | 11 | while(start<=end){ 12 | int mid=(start+end)/2; 13 | System.out.println(start+" "+end); 14 | if(ar[mid]==key) return mid; 15 | else if(ar[mid]>key) end=mid-1; 16 | else start=mid+1; 17 | } 18 | return -1; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ClaimStairsDP.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static int[] memo; 5 | public static void setLength(int n){ 6 | memo=new int[n]; 7 | Arrays.fill(memo,-1); 8 | } 9 | 10 | 11 | public static int claimStairs(int n){ 12 | if(n==-1) return 0; 13 | if(memo[n]!=-1){ 14 | return memo[n]; 15 | } 16 | else if(n==0){ 17 | memo[n]=1; 18 | return memo[n]; 19 | } 20 | else{ 21 | memo[n]=claimStairs(n-1)+claimStairs(n-2); 22 | return memo[n]; 23 | } 24 | } 25 | public static void main(String[] args) { 26 | int n=new Scanner(System.in).nextInt(); 27 | setLength(n+1); 28 | System.out.println(claimStairs(n)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CountingBits.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] countBits(int n) { 3 | int[] dp=new int[n+1]; 4 | dp[0]=0; 5 | for(int i=1;i<=n;i++){ 6 | dp[i]=dp[i/2]+i%2; 7 | } 8 | return dp; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /DPP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Krishna18062005/Data-Structures/3560dc0056457b3d83567356bf11513e2fb68002/DPP.png -------------------------------------------------------------------------------- /DesignALinkedList.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Node{ 3 | int data; 4 | Node next; 5 | Node(int data){ 6 | this.data=data; 7 | this.next=null; 8 | } 9 | } 10 | 11 | public class Main { 12 | public static void main(String[] args) { 13 | Node ls=new Node(4); 14 | Node head=ls; 15 | ls.next=new Node(5); 16 | ls=ls.next; 17 | ls.next=new Node(6); 18 | while(head!=null){ 19 | System.out.print(head.data+" "); 20 | head=head.next; 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Leetcode.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int timeRequiredToBuy(int[] tickets, int k) { 3 | int ans=0; 4 | while(tickets[k]!=0){ 5 | for(int i=0;i0){ 49 | // int[] suffix=new int[code.length]; 50 | // int s=0; 51 | // for(int i=0;icode.length+(k);j--){ 65 | // s+=code[j]; 66 | // } 67 | 68 | // for(int j=code.length+k-1;j>=0+k;j--){ 69 | // prefix[j-] 70 | // } 71 | // return prefix; 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /LinkedListpalindrome.java: -------------------------------------------------------------------------------- 1 | //{ Driver Code Starts 2 | // Initial Template for Java 3 | 4 | import java.io.*; 5 | import java.lang.*; 6 | import java.util.*; 7 | 8 | class Node { 9 | int data; 10 | Node next; 11 | 12 | Node(int data) { 13 | this.data = data; 14 | this.next = null; 15 | } 16 | } 17 | 18 | class Driver_code { 19 | static Node insert(Node head, int data) { 20 | Node temp = new Node(data); 21 | if (head == null) { 22 | head = temp; 23 | return head; 24 | } else { 25 | Node t = head; 26 | while (t.next != null) { 27 | t = t.next; 28 | } 29 | t.next = temp; 30 | } 31 | return head; 32 | } 33 | 34 | static void printList(Node head) { 35 | Node temp = head; 36 | while (temp != null) { 37 | System.out.print(temp.data + " "); 38 | temp = temp.next; 39 | } 40 | } 41 | 42 | public static void main(String[] args) throws IOException { 43 | BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); 44 | int t = Integer.parseInt(read.readLine()); 45 | 46 | while (t-- > 0) { 47 | 48 | Node head = null; 49 | 50 | String str[] = read.readLine().trim().split(" "); 51 | int listSize = str.length; 52 | for (int i = 0; i < listSize; i++) { 53 | head = insert(head, Integer.parseInt(str[i])); 54 | } 55 | boolean f = new Solution().isPalindrome(head); 56 | 57 | System.out.println(f ? "true" : "false"); 58 | } 59 | } 60 | } 61 | 62 | // } Driver Code Ends 63 | 64 | 65 | /* Structure of class Node is 66 | class Node 67 | { 68 | int data; 69 | Node next; 70 | 71 | Node(int d) 72 | { 73 | data = d; 74 | next = null; 75 | } 76 | }*/ 77 | 78 | class Solution { 79 | // Function to check whether the list is palindrome. 80 | boolean isPalindrome(Node head) { 81 | // Your code here 82 | Node copy=new Node(head.data); 83 | Node c1=head; 84 | 85 | Node curr=head,prev=null,next; 86 | while(curr!=null){ 87 | next=curr.next; 88 | copy.next=new Node(head.data); 89 | copy=copy.next; 90 | prev=curr; 91 | curr=next; 92 | } 93 | 94 | Node c2=prev; 95 | while(c2!=null){ 96 | if(c1.data!=c2.data) return false; 97 | 98 | c2=c2.next; 99 | c1=c1.next; 100 | } 101 | return true; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Memoization.java: -------------------------------------------------------------------------------- 1 | // import java.util.*; 2 | 3 | // public class Memoization { 4 | // public static int fib(int n,int[] memo){ 5 | // if(memo[n]!=-1){ 6 | // return memo[n]; 7 | // } 8 | // if(n<=1){ 9 | // memo[n]=n; 10 | // return memo[n]; 11 | 12 | // } 13 | // else { 14 | // memo[n]=fib(n-1,memo)+fib(n-2,memo); 15 | // return memo[n]; 16 | // } 17 | 18 | // } 19 | // public static void main(String[] args) { 20 | // int n=7; 21 | // int[] memo=new int[n+1]; 22 | // Arrays.fill(memo,-1); 23 | // System.out.println(fib(n,memo)); 24 | // System.out.println(Arrays.toString(memo)); 25 | // } 26 | // } 27 | 28 | 29 | import java.util.*; 30 | 31 | public class Main { 32 | static int[] memo; 33 | public static void setLength(int n){ 34 | memo=new int[n]; 35 | Arrays.fill(memo,-1); 36 | } 37 | 38 | static int s=0; 39 | public static int claimStairs(int n){ 40 | if(n==-1) return 0; 41 | if(memo[n]!=-1){ 42 | return memo[n]; 43 | } 44 | else if(n==0){ 45 | memo[n]=1; 46 | return memo[n]; 47 | } 48 | else{ 49 | memo[n]=claimStairs(n-1)+claimStairs(n-2); 50 | return memo[n]; 51 | } 52 | } 53 | public static int claimStair(int n){ 54 | if(n==0){ 55 | return 1; 56 | } 57 | else if (n==-1){ 58 | return 0; 59 | } 60 | else{ 61 | return claimStairs(n-1)+claimStairs(n-2); 62 | } 63 | } 64 | 65 | public static void main(String[] args) { 66 | int n=new Scanner(System.in).nextInt(); 67 | setLength(n+1); 68 | long st=(System.nanoTime()); 69 | System.out.println("Using Memoization "+claimStairs(n)); 70 | // System.out.println(Arrays.toString(memo)); 71 | long et=(System.nanoTime()); 72 | System.out.println("RunTime : "+(et-st)); 73 | System.out.println(); 74 | 75 | long str=(System.nanoTime()); 76 | System.out.println("Recursive Approach "+claimStair(n)); 77 | 78 | long etr=(System.nanoTime()); 79 | System.out.println("RunTime : "+(etr-str)); 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Time_Teller.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.time.LocalTime; 3 | 4 | public class ss { 5 | public static void main(String args[]) { 6 | String time = "11:23"; 7 | 8 | while (true) { 9 | LocalTime CurrentTime = LocalTime.now(); 10 | String ct = CurrentTime.toString().substring(0, 5); 11 | if (ct.equals(time)) { 12 | System.out.println("padinga bro time ipo " + time); 13 | break; 14 | } 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /designAStack.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class stack{ 3 | private int[] arr=new int[10]; 4 | private int top=-1; 5 | public void push(int data){ 6 | if(top==9) throw new stackException("Stack Overflow"); 7 | top++; 8 | arr[top]=data; 9 | return true; 10 | 11 | } 12 | public boolean isEmpty(){ 13 | return top == -1; 14 | } 15 | public boolean isFull(){ 16 | return top == 9; 17 | } 18 | public int pop(){ 19 | if(top!=-1){ 20 | int data=arr[top]; 21 | top--; 22 | return data;} 23 | return -1; 24 | } 25 | public int peek(){ 26 | return arr[top]; 27 | } 28 | } 29 | 30 | public class Main { 31 | public static void main(String[] args) throws Exception{ 32 | stack s=new stack(); 33 | s.push(10); 34 | s.push(20); 35 | System.out.println(s.pop()); 36 | System.out.println(s.peek()); 37 | System.out.println(s.isEmpty()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hello.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Hello { 3 | public static void main(String[] args) { 4 | //Matrix same Characters 5 | Scanner sc=new Scanner(System.in); 6 | int N=sc.nextInt(); 7 | if(N<=1){ System.out.print("YES"); 8 | return;} 9 | boolean rslt; 10 | char[][] matri=new char[N][N]; 11 | for(int i=0;i 0) { 42 | int data = s.pop(); 43 | s.push(num % 10); 44 | data = data * 10 + s.pop(); 45 | s.push(data); 46 | num /= 10; 47 | } 48 | 49 | System.out.println(s.pop()); 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /springboot.java: -------------------------------------------------------------------------------- 1 | /*spring is a java framework 2 | 3 | 4 | we take an opinionated view of spring platform,if you want it can be changed 5 | springboot we can integrated any framework 6 | jar java archive file zipped file 7 | war file contains web related servers it provides database too 8 | jsp java server pages 9 | spring features: 10 | ioc---> inversion of Controller --> it creates objects mautomatically 11 | pojo - its a class file its a encapsulated file plain old object,dependency 12 | object,dependency injection,rest Api 13 | class file private variables ,getter and setter methods 14 | wee add dependencies on xml file 15 | maven package la add pandra object than dependencies injection 16 | mvc --> model view controller model--> data structure view--> defines 17 | display,controller --> control logic 18 | mvc allows only java 19 | spring framework allows dynamic languages 20 | group id package name 21 | artifact if file name 22 | 23 | jar for java project -->version if web use war; 24 | install steps 25 | extract contents 26 | open sts422 release...; 27 | 28 | public class springboot{ 29 | private int a; 30 | private int b; 31 | public void setter(){ 32 | a=8; 33 | b=9; 34 | } 35 | public void getter(){ 36 | System.out.println(a+" "+b); 37 | } 38 | 39 | }*/ 40 | --------------------------------------------------------------------------------