├── .DS_Store ├── Contest1.java ├── Module 2 January ├── .DS_Store ├── Contest Discussion 1.pdf ├── Contest1Discussion.java ├── ContestDiscussion2.java ├── ContestDiscussion2.pdf ├── LinkedList.pdf ├── LinkedList │ ├── Main.class │ ├── Main.java │ └── Node.class ├── Merge sort And Quick sort.pdf ├── OOPS.pdf ├── OOPS │ ├── .DS_Store │ ├── Abstraction │ │ ├── .DS_Store │ │ ├── Interface.java │ │ ├── Main.java │ │ └── MultipleInheritance.java │ ├── Acess Modifiers │ │ ├── .DS_Store │ │ ├── FOlderB │ │ │ ├── .DS_Store │ │ │ ├── B.java │ │ │ └── FolderA │ │ │ │ ├── .DS_Store │ │ │ │ └── A.java │ │ └── Main.java │ ├── Encapsulation │ │ ├── .DS_Store │ │ └── Main.java │ ├── Inheritance │ │ ├── .DS_Store │ │ ├── Example.java │ │ ├── Main.java │ │ └── MultiLevelInheritance.java │ ├── Introduction │ │ ├── .DS_Store │ │ ├── ConstructorChaining.java │ │ ├── ConstructorExample.java │ │ ├── Main.java │ │ └── ThisKeywordExample.java │ ├── Pizza Bill Generator Project │ │ ├── DeluxePizza.java │ │ ├── Main.java │ │ ├── Pizza.java │ │ └── Question.txt │ ├── PolyMorphism │ │ ├── .DS_Store │ │ ├── Example.java │ │ ├── Main.java │ │ └── MethodOverriding.java │ ├── Static Keyword │ │ ├── .DS_Store │ │ ├── Example.java │ │ ├── Example2.java │ │ └── Main.java │ └── Wrapper Classes │ │ └── Main.java ├── Recursion.pdf └── Recursion │ ├── ArrayListExample.class │ ├── ArrayListExample.java │ ├── MergeSort and QuickSort │ ├── MergeSort.class │ ├── MergeSort.java │ ├── QuickSort.class │ └── QuickSort.java │ ├── Recursion With Integers │ ├── Main.class │ └── Main.java │ ├── Recursion With Strings (Print Types) │ ├── Main.class │ └── Main.java │ ├── Recursion with Arrays │ ├── Main.class │ ├── Main.java │ ├── Questions.class │ └── Questions.java │ └── Recursion with Strings │ ├── GetTypes.class │ ├── GetTypes.java │ ├── Main.class │ └── Main.java ├── Module 2 ├── .DS_Store ├── Linked List .pdf ├── LinkedList │ ├── .DS_Store │ ├── ContestDiscussion │ │ └── Main.java │ ├── Introduction │ │ ├── Main.class │ │ ├── Main.java │ │ └── Node.class │ └── Questions │ │ └── Main.java ├── OOPS │ ├── 07_11_2022 │ │ ├── Car.class │ │ ├── CounterExample.java │ │ ├── Hyundai.class │ │ ├── Inheritance.class │ │ ├── Inheritance.java │ │ ├── MultiLevelInheritance.java │ │ ├── StaticExample.java │ │ ├── StaticMethods.java │ │ └── Vechile.class │ ├── 08_11_2022 │ │ ├── Accio.class │ │ ├── Accio.java │ │ ├── ConstructorChaining.java │ │ ├── ConstructorChaining2.java │ │ ├── Example.class │ │ ├── Example.java │ │ ├── Main.class │ │ ├── Main.java │ │ ├── PolyMorphism │ │ │ ├── Example.java │ │ │ ├── MethodOverRiding.java │ │ │ └── MethodOverloading.java │ │ ├── Student.class │ │ └── SuperKeyword.java │ ├── 09_11_2022 │ │ ├── A.class │ │ ├── A │ │ │ └── File1.java │ │ ├── Abstraction.class │ │ ├── Abstraction.java │ │ ├── AbstractionExample.class │ │ ├── AbstractionExample.java │ │ ├── B.class │ │ ├── B │ │ │ └── File2.java │ │ ├── Car.class │ │ ├── Child.class │ │ ├── Circle.class │ │ ├── Encapsulation.java │ │ ├── Final.java │ │ ├── InterfaceExample.class │ │ ├── InterfaceExample.java │ │ ├── MultipleInheritance.class │ │ ├── MultipleInheritance.java │ │ ├── Rectangle.class │ │ ├── Shape.class │ │ └── Student.class │ └── Class 1 │ │ ├── Car.class │ │ ├── OOP.class │ │ ├── OOP.java │ │ └── Student.class ├── OOPs.pdf ├── Recursion.pdf ├── Recursion │ ├── Class 1 │ │ ├── Main.java │ │ ├── PrintDecreasing.class │ │ └── PrintDecreasing.java │ ├── Class 2 │ │ ├── Main.class │ │ └── Main.java │ ├── Class 3, Recursion with Arrays │ │ └── Main.java │ ├── Class 4 │ │ ├── Main.class │ │ ├── Main.java │ │ └── robHouse.java │ ├── ContestQuestions.java │ └── RecursionRevision │ │ ├── Main.class │ │ └── Main.java ├── Revision.pdf ├── Two Pointers.pdf └── Two Pointers │ └── Questions.java ├── Module 5 ├── .DS_Store ├── BT + DP.pdf ├── BT.pdf ├── Backtracking .pdf ├── Backtracking │ ├── Day 2 │ │ ├── CombinationPermutation.class │ │ ├── CombinationPermutation.java │ │ ├── Main.java │ │ └── out.txt │ ├── Day 3 │ │ └── PnC.java │ └── Recursion Problem │ │ ├── Main.class │ │ └── Main.java ├── Buy and Sell stocks.pdf ├── CUT TYPE.pdf ├── Contest Discussion 2.pdf ├── Contest1.java ├── Contest2.java ├── DP.pdf ├── Dynamic Programming module 5.pdf ├── Dynamic Programming │ ├── 2D DP │ │ └── Main.java │ ├── Buy_and_sell_stocks.java │ ├── Cut Type DP │ │ ├── Catalan.java │ │ └── Main.java │ ├── Introduction │ │ ├── Main.class │ │ ├── Main.java │ │ └── Questions.java │ ├── LIS set │ │ ├── Main.class │ │ └── Main.java │ ├── Misc │ │ └── Main.java │ └── String set │ │ └── Main.java ├── Graph.pdf ├── Graph │ ├── BFS │ │ ├── Main$Edge.class │ │ ├── Main.class │ │ ├── Main.java │ │ └── out.txt │ ├── DFS Questions │ │ └── Main.java │ └── Introduction │ │ ├── Graph$Edge.class │ │ ├── Graph.class │ │ ├── Graph.java │ │ ├── Questions.java │ │ └── out.txt ├── Heap.pdf ├── Heap │ ├── Example.class │ ├── Example.java │ ├── Implementation$Heap.class │ ├── Implementation.class │ ├── Implementation.java │ ├── ImplementationMax$MaxHeap.class │ ├── ImplementationMax.class │ ├── ImplementationMax.java │ ├── PQIntroduction.class │ ├── PQIntroduction.java │ ├── Questions.java │ └── Student.class └── String DP.pdf ├── Offline ├── .DS_Store ├── 2D Arrays │ ├── Introduction │ │ ├── Main.class │ │ └── Main.java │ └── Questions │ │ └── Main.java ├── ArrayList │ ├── Introduction │ │ ├── Main.class │ │ └── Main.java │ └── Questions │ │ ├── Main.class │ │ └── Main.java ├── Arrays │ ├── Introduction │ │ ├── Main.class │ │ ├── Main.java │ │ └── Swap.java │ └── Questions │ │ └── Main.java ├── Class 2 │ ├── Conditionals │ │ ├── Calculator.class │ │ ├── Calculator.java │ │ ├── Main.class │ │ ├── Main.java │ │ ├── ReportCard.class │ │ └── ReportCard.java │ ├── Main.java │ ├── Questions.class │ └── Questions.java ├── Functions │ └── Questions │ │ ├── Main.class │ │ └── Main.java ├── Introduction │ ├── Main.class │ ├── Main.java │ └── Questions.java ├── LinkedList │ ├── Design Browser History │ │ └── Main.java │ ├── Introduction │ │ ├── LinkedList$Node.class │ │ ├── LinkedList.class │ │ ├── Main.class │ │ ├── Main.java │ │ └── Node.class │ └── Questions │ │ └── Main.java ├── Loops │ ├── Example.class │ ├── Example.java │ ├── Main.java │ ├── NumberPatterns │ │ ├── Main.class │ │ └── Main.java │ └── Patterns │ │ ├── DiamondPattern.java │ │ ├── Main.class │ │ └── Main.java ├── OOPS │ ├── Abstraction │ │ ├── A.class │ │ ├── A.java │ │ ├── Car.class │ │ ├── Circle.class │ │ ├── Main.class │ │ ├── Main.java │ │ ├── Reactagle.class │ │ ├── Rectagle.class │ │ ├── Shape.class │ │ ├── V.class │ │ └── Vechile.class │ ├── Constructors │ │ ├── ConstructorChaining.class │ │ ├── ContructorChaining.class │ │ ├── ContructorChaining.java │ │ ├── Main.class │ │ ├── Main.java │ │ ├── Student.class │ │ └── Vechile.class │ ├── Inheritance │ │ ├── Bike.class │ │ ├── Car.class │ │ ├── Hyundai.class │ │ ├── Main.class │ │ ├── Main.java │ │ └── Vechile.class │ ├── Introduction │ │ ├── Main.class │ │ ├── Main.java │ │ └── Student.class │ ├── PizzaGenerator │ │ ├── DeluxePizza.class │ │ ├── DeluxePizza.java │ │ ├── Main.class │ │ ├── Main.java │ │ ├── Pizza.class │ │ └── Pizza.java │ ├── PolyMorphism │ │ ├── Bike.class │ │ ├── Car.class │ │ ├── Example.java │ │ ├── Main.class │ │ ├── Main.java │ │ └── Vechile.class │ ├── Questions │ │ └── Main.java │ ├── Static Keyword │ │ ├── Example.java │ │ ├── Main.class │ │ ├── Main.java │ │ └── Student.class │ └── encapsulation │ │ ├── Employee.class │ │ ├── Main.class │ │ ├── Main.java │ │ ├── Main2.java │ │ ├── Question.class │ │ ├── Question.java │ │ ├── Student.class │ │ ├── Vechile.class │ │ └── Vechile.java ├── Recursion │ ├── Backtracking │ │ └── Main.java │ ├── Get Questions │ │ ├── Main.class │ │ └── Main.java │ ├── IQuestions │ │ ├── Main.class │ │ └── Main.java │ ├── Introduction │ │ ├── Main.class │ │ └── Main.java │ ├── Print Questions │ │ ├── Main.class │ │ └── Main.java │ ├── Questions │ │ ├── Main.class │ │ └── Main.java │ ├── Recursion in Arrays │ │ ├── Main.class │ │ └── Main.java │ └── Sorting │ │ ├── Main.class │ │ └── Main.java └── Strings │ ├── Introduction │ ├── Main.class │ └── Main.java │ └── Questions │ ├── Main.class │ └── Main.java └── Sapling 1 └── Introduction.pdf /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/.DS_Store -------------------------------------------------------------------------------- /Contest1.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Contest1.java -------------------------------------------------------------------------------- /Module 2 January/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/Contest Discussion 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/Contest Discussion 1.pdf -------------------------------------------------------------------------------- /Module 2 January/Contest1Discussion.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class Contest1Discussion { 4 | // Questions ============================== 5 | // https://course.acciojob.com/idle?question=c8f615fa-39c6-43e8-8b66-79bd84811e79 6 | // https://course.acciojob.com/idle?question=df08a8b0-60db-4bdb-9b0b-38b7755086e1 7 | // https://course.acciojob.com/idle?question=6d37d97f-e4d9-4d08-8bde-d3a971bc5cda 8 | public static int fourbinacci(int n) { 9 | if(n<=4){ 10 | return 1; 11 | } 12 | 13 | int lt = fourbinacci(n-1); 14 | int lst = fourbinacci(n-2); 15 | int ltt = fourbinacci(n-3); 16 | int lft = fourbinacci(n-4); 17 | 18 | int ans = lt + lst + ltt + lft; 19 | return ans; 20 | } 21 | 22 | public static int deathGame(int n, int k) { 23 | ArrayList al = new ArrayList<>(); 24 | 25 | for(int i=1; i<=n; i++){ 26 | al.add(i); 27 | } 28 | 29 | // k--; 30 | int idx=0; 31 | while(al.size()>1){ 32 | int personToKill = (idx+(k-1))%al.size(); // why k-1, because we are counting current idx as well 33 | al.remove(personToKill); 34 | 35 | idx = personToKill; 36 | } 37 | 38 | return al.get(0); 39 | } 40 | 41 | public static boolean isLuckyNumber(int num){ 42 | if(num==1){ 43 | return true; 44 | } 45 | if(num==89){ 46 | return false; 47 | } 48 | 49 | int sumOfSquareDigits = 0; 50 | 51 | while(num>0){ 52 | int rem = num%10; 53 | sumOfSquareDigits += rem*rem; 54 | 55 | num/=10; 56 | } 57 | 58 | boolean ans= isLuckyNumber(sumOfSquareDigits); 59 | return ans; 60 | } 61 | 62 | static int solve(int n) { 63 | for(int i=n+1; i<=10000; i++){ 64 | boolean luckyNumber = isLuckyNumber(i); 65 | if(luckyNumber == true){ 66 | return i; 67 | } 68 | } 69 | 70 | return -1; 71 | } 72 | 73 | public static void main(String[] args) { 74 | // int n = 20; 75 | // int ans = fourbinacci(n); 76 | // System.out.println(ans); 77 | 78 | // int n= 5, k=2; 79 | // int ans = deathGame(n, k); 80 | // System.out.println(ans); 81 | 82 | int n = 10; 83 | int nextLuckyNumber = solve(n); 84 | System.out.println(nextLuckyNumber); 85 | } 86 | } -------------------------------------------------------------------------------- /Module 2 January/ContestDiscussion2.java: -------------------------------------------------------------------------------- 1 | public class ContestDiscussion2 { 2 | // https://course.acciojob.com/idle?question=f2ab38ff-370b-4417-9bc6-97ece3b4cf1f 3 | public boolean isMagical(int n, int itrNum){ 4 | if(itrNum > n){ 5 | return true; 6 | } 7 | if(n % itrNum == 0){ 8 | return false; 9 | } 10 | 11 | int next_pos = n - (n/itrNum); 12 | return isMagical(next_pos, itrNum + 1); 13 | } 14 | 15 | public boolean solve(int n) { 16 | return isMagical(n,2); 17 | } 18 | 19 | // leetcode 486, https://course.acciojob.com/idle?question=b4dfaf91-ed01-447d-b3bc-a34a30b5c38e 20 | public int findMax(int[] arr, int i, int j){ 21 | if(i>j){ 22 | return 0; 23 | } 24 | 25 | int firstElement = arr[i] + Math.min(findMax(arr,i+2,j), findMax(arr, i+1, j-1)); 26 | int lastElement = arr[j] + Math.min(findMax(arr,i+1,j-1), findMax(arr, i, j-2)); 27 | 28 | int ans = Math.max(firstElement, lastElement); 29 | return ans; 30 | } 31 | 32 | public boolean solve(int n,int arr[]) 33 | { 34 | int sum = 0; 35 | for(int i=0; i=aliceScore){ 42 | return true; 43 | } else { 44 | return false; 45 | } 46 | // return alexScore >= aliceScore; 47 | } 48 | 49 | // leetcode 390, https://course.acciojob.com/idle?question=f0c7ce37-b542-44c2-ad19-95f824a16af0 50 | public int solve_rec(int start, int diff, boolean left, int noe){ 51 | if(noe==1){ 52 | return start; 53 | } 54 | 55 | if(left == true){ 56 | start = start + diff; 57 | return solve_rec(start, diff*2, false, noe/2); 58 | } else { 59 | if(noe%2!=0){ 60 | start = start+diff; 61 | } 62 | return solve_rec(start, diff*2, true, noe/2); 63 | } 64 | } 65 | public int solve(int n){ 66 | return solve_rec(1,1,true,n); 67 | } 68 | public static void main(String[] args) { 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Module 2 January/ContestDiscussion2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/ContestDiscussion2.pdf -------------------------------------------------------------------------------- /Module 2 January/LinkedList.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/LinkedList.pdf -------------------------------------------------------------------------------- /Module 2 January/LinkedList/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/LinkedList/Main.class -------------------------------------------------------------------------------- /Module 2 January/LinkedList/Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/LinkedList/Node.class -------------------------------------------------------------------------------- /Module 2 January/Merge sort And Quick sort.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/Merge sort And Quick sort.pdf -------------------------------------------------------------------------------- /Module 2 January/OOPS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS.pdf -------------------------------------------------------------------------------- /Module 2 January/OOPS/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Abstraction/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Abstraction/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Abstraction/Interface.java: -------------------------------------------------------------------------------- 1 | interface Shape { 2 | int a = 52; // by default this is final 3 | void display(); // -> public abstract void display(); 4 | void Honk();// -> public abstract void Honk(); 5 | } 6 | 7 | 8 | class Circle implements Shape { 9 | public void display(){ 10 | // a = 54; // cannot assign a value to final variable a 11 | System.out.println("display functionn"); 12 | } 13 | 14 | public void Honk(){ 15 | System.out.println("Honk functionn"); 16 | } 17 | } 18 | public class Interface { 19 | public static void main(String[] args) { 20 | Circle c = new Circle(); 21 | c.display(); 22 | c.Honk(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Abstraction/Main.java: -------------------------------------------------------------------------------- 1 | abstract class Vehicle { 2 | abstract public void display(); 3 | 4 | public void fun(){ 5 | System.out.println("Non abstract function"); 6 | } 7 | } 8 | 9 | class Car extends Vehicle { 10 | public void display(){ 11 | System.out.println("Defining abstact function"); 12 | } 13 | } 14 | 15 | abstract class Shape { 16 | abstract void displayShape(); 17 | } 18 | 19 | class Circle extends Shape { 20 | void displayShape(){ 21 | System.out.println("Its a circle"); 22 | } 23 | } 24 | 25 | class Rectange extends Shape { 26 | void displayShape(){ 27 | System.out.println("Its a Rectangle"); 28 | } 29 | } 30 | 31 | public class Main { 32 | public static void main(String[] args) { 33 | // Vehicle v = new Car(); 34 | 35 | // v.display(); 36 | Shape s = new Circle(); 37 | s.displayShape(); 38 | 39 | s = new Rectange(); 40 | s.displayShape(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Abstraction/MultipleInheritance.java: -------------------------------------------------------------------------------- 1 | interface A { 2 | void display(); 3 | } 4 | 5 | interface B { 6 | void display(); 7 | } 8 | 9 | interface D { 10 | void honk(); 11 | } 12 | 13 | // multiple inheritance 14 | class C implements A,B,D { 15 | public void display(){ 16 | System.out.println("display"); 17 | } 18 | 19 | public void honk(){ 20 | System.out.println("Honk"); 21 | } 22 | } 23 | 24 | public class MultipleInheritance { 25 | public static void main(String[] args) { 26 | C obj = new C(); 27 | obj.display(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Acess Modifiers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Acess Modifiers/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Acess Modifiers/FOlderB/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Acess Modifiers/FOlderB/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Acess Modifiers/FOlderB/B.java: -------------------------------------------------------------------------------- 1 | import FolderA.A; 2 | public class B extends A { 3 | public static void main(String[] args) { 4 | A obj = new A(); 5 | // B obj = new B(); 6 | obj.fun(); 7 | // obj.display(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Acess Modifiers/FOlderB/FolderA/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Acess Modifiers/FOlderB/FolderA/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Acess Modifiers/FOlderB/FolderA/A.java: -------------------------------------------------------------------------------- 1 | package FolderA; 2 | public class A { 3 | void fun(){ 4 | System.out.println("Displaying funnnnnn from the A classs"); 5 | } 6 | protected void display(){ 7 | System.out.println("Displaying from the A classs"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Acess Modifiers/Main.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | private int roll_no = 50; 3 | 4 | private void display(){ 5 | roll_no++; 6 | System.out.println("Displaying"); 7 | } 8 | } 9 | 10 | class smallStudent extends Student { 11 | public void increaseRoll_no(){ 12 | // super.roll_no++; // compile time error 13 | } 14 | } 15 | 16 | public class Main { 17 | public static void main(String[] args) { 18 | Student s = new Student(); 19 | // s.display(); 20 | // s.roll_no = 49; not allowed 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Encapsulation/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Encapsulation/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Encapsulation/Main.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | int roll_no; 4 | private int marks; 5 | 6 | public Student(String name, int roll_no, int marks){ 7 | this.name = name; 8 | this.roll_no = roll_no; 9 | this.marks = marks; 10 | } 11 | 12 | // getter 13 | public int getMarks(){ 14 | return this.marks; 15 | } 16 | 17 | // setters 18 | public void setMarks(int marks){ 19 | if(marks >=100){ 20 | System.out.println("Dont cheat !!!!!!!!"); 21 | return; 22 | } 23 | this.marks = marks; 24 | } 25 | } 26 | 27 | public class Main { 28 | public static void main(String[] args) { 29 | Student s1 = new Student("Rajesh", 12, 50); 30 | 31 | s1.setMarks(100); 32 | System.out.println(s1.getMarks()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Inheritance /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Inheritance /.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Inheritance /Example.java: -------------------------------------------------------------------------------- 1 | class Vehicle { 2 | String color; 3 | int seats; 4 | 5 | public Vehicle(){ 6 | // System.out.println("Default constructor"); 7 | } 8 | 9 | public Vehicle(String color, int seats){ 10 | System.out.println("Parametrized constructor"); 11 | this.color = color; 12 | this.seats = seats; 13 | } 14 | 15 | public void Vehiclehonk(){ 16 | System.out.println("Honking from the vehicle class"); 17 | } 18 | } 19 | 20 | class Car extends Vehicle { 21 | int engine=47; 22 | 23 | public Car(){ 24 | 25 | } 26 | public Car(String color, int seats, int engine){ 27 | super(color, seats); 28 | this.engine = engine; 29 | } 30 | 31 | public void Vehiclehonk(){ 32 | System.out.println("Honking from the Car class but vehicle"); 33 | } 34 | 35 | public void CarHonk(){ 36 | System.out.println("Honking from the car!!!!!!"); 37 | this.Vehiclehonk(); 38 | } 39 | 40 | public void doSomething(int engine){ 41 | this.engine++; 42 | } 43 | 44 | public void doSomethingAgain(int seats){ 45 | // super.seats++; 46 | // this.seats++; 47 | System.out.println(seats); 48 | } 49 | } 50 | 51 | class Hyundai extends Car { 52 | int model_number; 53 | 54 | public void HonkHonk(){ 55 | super.Vehiclehonk(); 56 | } 57 | 58 | public void increaseSeats(){ 59 | super.seats++; 60 | } 61 | } 62 | 63 | 64 | public class Example { 65 | public static void main(String[] args) { 66 | // Car c1 = new Car(); 67 | // c1.seats = 4; 68 | // c1.doSomethingAgain(34); 69 | // System.out.println(c1.seats); 70 | 71 | Hyundai h = new Hyundai(); 72 | h.HonkHonk(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Inheritance /Main.java: -------------------------------------------------------------------------------- 1 | class Vechile { //-> parent class / super class 2 | int now = 2; // number of wheels 3 | String color; 4 | 5 | public Vechile(){ 6 | System.out.println("Constructor from vehicle class is called"); 7 | } 8 | 9 | public void honk(){ 10 | System.out.println("Honking from Vechile class"); 11 | } 12 | } 13 | 14 | class Car extends Vechile { // child class / sub class 15 | int horsePowers; 16 | 17 | public Car(){ 18 | System.out.println("Constructor from Car class is called"); 19 | } 20 | 21 | public void run(){ 22 | System.out.println("Running from child class"); 23 | } 24 | } 25 | 26 | class Bike extends Vechile { 27 | int maxSpeed; 28 | 29 | public Bike(){ 30 | System.out.println("Bike constructor"); 31 | } 32 | } 33 | 34 | public class Main { 35 | public static void main(String[] args) { 36 | // Vechile v1 = new Vechile(); 37 | // Car c1 = new Car(); 38 | // c1.now = 4; 39 | // c1.color= "Red"; 40 | // c1.horsePowers = 400; 41 | 42 | // c1.honk(); 43 | // c1.run(); 44 | 45 | Bike b1 = new Bike(); 46 | // b1.now = 2; 47 | // b1.honk(); 48 | // b1.maxSpeed=400; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Inheritance /MultiLevelInheritance.java: -------------------------------------------------------------------------------- 1 | class GrandParent { 2 | int radio; 3 | 4 | public GrandParent(){ 5 | System.out.println("GrandParent constructor"); 6 | } 7 | } 8 | 9 | class Parent extends GrandParent { 10 | int TV; 11 | 12 | public Parent(){ 13 | System.out.println("Parent constructor"); 14 | } 15 | } 16 | 17 | class Child extends Parent { 18 | int smartPhone; 19 | 20 | public Child(){ 21 | System.out.println("Child constructor"); 22 | } 23 | } 24 | public class MultiLevelInheritance { 25 | public static void main(String[] args) { 26 | Child c1 = new Child(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Introduction/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Introduction/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Introduction/ConstructorChaining.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | int age; 4 | int roll_no; 5 | 6 | public Student(){ 7 | System.out.println("Default constructor is called"); 8 | } 9 | 10 | public Student(String name){ 11 | this.name = name; 12 | System.out.println("constructor 1 is called"); 13 | } 14 | 15 | public Student(String name, int age){ 16 | this(name); 17 | System.out.println("constructor 2 is called"); 18 | } 19 | 20 | public Student(String name, int age, int roll_no){ 21 | this(name,age); 22 | this.roll_no = roll_no; 23 | System.out.println("constructor 3 is called"); 24 | } 25 | } 26 | 27 | public class ConstructorChaining { 28 | public static void main(String[] args) { 29 | // Student s1 = new Student(); 30 | // Student s2 = new Student("Accio"); 31 | Student s3 = new Student("Accio",12,234); 32 | // Student s4 = new Student("Accio",45); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Introduction/ConstructorExample.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name = "CE"; 3 | int age = 1336; 4 | int roll_no = -10; 5 | 6 | // default constructor 7 | public Student(){ 8 | System.out.println("Constructor 1 is called"); 9 | } 10 | 11 | // parametrized constructor 12 | public Student(String newName, int newAge, int newRoll_no){ 13 | System.out.println("Constructor 2 is called"); 14 | name = newName; 15 | age = newAge; 16 | roll_no = newRoll_no; 17 | } 18 | 19 | public Student(int newAge, int newRoll_no){ 20 | System.out.println("Constructor 3 is called"); 21 | System.out.println(age); 22 | age = newAge; 23 | roll_no = newRoll_no; 24 | } 25 | } 26 | 27 | public class ConstructorExample { 28 | public static void main(String[] args) { 29 | // Student s1 = new Student("Mahesh",11,1); 30 | Student s2 = new Student(); 31 | // Student s3 = new Student(-100,-200); 32 | 33 | // System.out.println("Student Object with properties "+s1.name+" "+s1.age+" "+s1.roll_no); 34 | // System.out.println("Student Object with properties "+s2.name+" "+s2.age+" "+s2.roll_no); 35 | // System.out.println("Student Object with properties "+s3.name+" "+s3.age+" "+s3.roll_no); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Introduction/Main.java: -------------------------------------------------------------------------------- 1 | // blueprint for student 2 | class Student { 3 | String name = "Accio"; 4 | int age = 13; 5 | int roll_no = 1; 6 | 7 | public void makeNoise(){ 8 | System.out.println("Making noise from "+name); 9 | } 10 | 11 | public void increaseAge(){ 12 | age++; 13 | } 14 | } 15 | 16 | public class Main { 17 | public static void main(String[] args) { 18 | Student s1 = new Student(); 19 | System.out.println("Properties of s1 -> " + s1.name+" "+s1.age+" "+s1.roll_no); 20 | 21 | s1.name = "Mahesh"; 22 | s1.age = 11; 23 | s1.roll_no = 10; 24 | 25 | Student s2 = new Student(); 26 | s2.name = "Rajesh"; 27 | s2.age = 12; 28 | s2.roll_no = 11; 29 | 30 | System.out.println("Properties of s1 -> " + s1.name+" "+s1.age+" "+s1.roll_no); 31 | // System.out.println("Properties of s2 -> " + s2.name+" "+s2.age+" "+s2.roll_no); 32 | 33 | // s1.makeNoise(); 34 | // s2.makeNoise(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Introduction/ThisKeywordExample.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name = "CE"; 3 | int age = 1336; 4 | 5 | public void fun(int age){ 6 | this.age++; 7 | // this.fun(); 8 | } 9 | 10 | public Student(String name, int age){ 11 | this.name = name; 12 | this.age = age; 13 | } 14 | } 15 | public class ThisKeywordExample { 16 | public static void main(String[] args) { 17 | Student s1 = new Student("Accio",23); 18 | 19 | s1.fun(100); 20 | 21 | System.out.println(s1.age); 22 | // System.out.println(s1.name+" "+s1.age); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Pizza Bill Generator Project/DeluxePizza.java: -------------------------------------------------------------------------------- 1 | public class DeluxePizza extends Pizza { 2 | 3 | public DeluxePizza(Boolean isVeg) { 4 | super(isVeg); // normal pizza 5 | addExtraCheese(); 6 | addExtraToppings(); 7 | } 8 | } -------------------------------------------------------------------------------- /Module 2 January/OOPS/Pizza Bill Generator Project/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | // Pizza rp = new Pizza(true); // veg pizza 4 | // rp.addExtraToppings(); 5 | // rp.addExtraCheese(); 6 | // rp.addExtraCheese(); 7 | // rp.addExtraCheese(); 8 | // rp.addExtraToppings(); 9 | // rp.addTakeaway(); 10 | 11 | DeluxePizza dp = new DeluxePizza(false); 12 | dp.addExtraCheese(); 13 | dp.addExtraCheese(); 14 | dp.addExtraToppings(); 15 | dp.addTakeaway(); 16 | 17 | System.out.println(dp.getBill()); 18 | } 19 | } -------------------------------------------------------------------------------- /Module 2 January/OOPS/Pizza Bill Generator Project/Pizza.java: -------------------------------------------------------------------------------- 1 | public class Pizza { 2 | private boolean isVeg; // if its a veg pizza (isVeg = true) else if non veg (isVeg=false) 3 | 4 | private String bill=""; 5 | private int price=0; 6 | private boolean isCheeseAddedOnce = false; 7 | private boolean isToppingsAddedOnce = false; 8 | private boolean isTakeAwayAdded = false; 9 | 10 | // given prices that we can change 11 | private int vegPizzaBasePrice = 300; 12 | private int NonvegPizzaBasePrice = 400; 13 | private int extraCheesePrice = 80; 14 | private int extraToppingsVegPrice = 70; 15 | private int extraToppingsNonVegPrice = 120; 16 | private int TakeAwayPrice = 20; 17 | 18 | 19 | public Pizza(boolean isVeg){ 20 | this.isVeg = isVeg; 21 | 22 | if(isVeg == true){ 23 | price += vegPizzaBasePrice; 24 | bill = bill + "Base Price Of The Pizza: " + vegPizzaBasePrice + "\n"; 25 | } else { 26 | price += NonvegPizzaBasePrice; 27 | bill = bill + "Base Price Of The Pizza: " + NonvegPizzaBasePrice + "\n"; 28 | } 29 | } 30 | 31 | public int getPrice(){ 32 | return this.price; 33 | } 34 | 35 | public void addExtraCheese(){ 36 | if(isCheeseAddedOnce == false){ 37 | price = price + extraCheesePrice; 38 | 39 | isCheeseAddedOnce = true; 40 | } 41 | } 42 | 43 | public void addExtraToppings(){ 44 | if(isToppingsAddedOnce == false){ 45 | if(isVeg == true){ 46 | this.price += extraToppingsVegPrice; 47 | } else { 48 | this.price += extraToppingsNonVegPrice; 49 | } 50 | 51 | isToppingsAddedOnce = true; 52 | } 53 | } 54 | 55 | public void addTakeaway(){ 56 | isTakeAwayAdded = true; 57 | this.price += TakeAwayPrice; 58 | } 59 | 60 | public String getBill(){ 61 | if(isCheeseAddedOnce==true){ 62 | this.bill = this.bill + "Extra Cheese Added: " + extraCheesePrice + "\n"; 63 | } 64 | 65 | if(isToppingsAddedOnce){ 66 | if(isVeg == true){ 67 | this.bill = this.bill + "Extra Toppings Added: " + extraToppingsVegPrice +"\n"; 68 | } else { 69 | this.bill = this.bill + "Extra Toppings Added: " + extraToppingsNonVegPrice +"\n"; 70 | } 71 | } 72 | 73 | if(isTakeAwayAdded){ 74 | this.bill = this.bill + "Paperbag Added: " + TakeAwayPrice +"\n"; 75 | } 76 | 77 | this.bill = this.bill + "Total price: " + this.price; 78 | 79 | return this.bill; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Pizza Bill Generator Project/Question.txt: -------------------------------------------------------------------------------- 1 | https://course.acciojob.com/idle?question=271c50f1-992a-48fd-b19b-344a3 2 | 3 | 4 | Pizza Bill Generator: 5 | In a pizza cafe there are two types of pizzas, regular and deluxe, and both come in their veg and non-veg variants with a base price. 6 | You can ask to add extra cheese or toppings if you want on your regular pizza. Deluxe Pizza comes with extra cheese and toppings by default. 7 | Also, if you want a takeaway you have to pay for the paper bag that comes with it. In the end you need to generate a bill for the customers. 8 | 9 | Veg pizza base price = 300 10 | Non-veg pizza base price = 400 11 | Extra Cheese Price = 80 12 | Extra Toppings For Veg Pizza = 70 13 | Extra Toppings For Non-veg Pizza = 120 14 | Paper bag Price = 20 15 | 16 | You are given three classes in your driver code. Main.java, Pizza.java and DeluxePizza.java. Your DeluxePizza class should extends Pizza class 17 | and it shouldn’t have any extra methods in DeluxePizza class, i.e. make sure it’s constructor takes care of extra cheese and toppings. You have to 18 | complete the skeleton code in order to make your app work. 19 | 20 | Bill Structure Example: 21 | 22 | Example 1: 23 | Base Price Of The Pizza: 300 24 | Extra Cheese Added: 80 25 | Extra Toppings Added: 70 26 | Paperbag Added: 20 27 | Total Price: 470 28 | 29 | Example 2: 30 | Base Price Of The Pizza: 400 31 | Extra Cheese Added: 80 32 | Extra Toppings Added: 120 33 | Total Price: 600 34 | 35 | Note: 36 | The customer might ask for extra cheese or toppings by invoking your method multiple times, but you have to make sure you don’t add it in the bill multiple times. 37 | Make sure you add extra cheese before the extra toppings if a customer asks for both and it reflect the same in the billing. 38 | In the billing make sure the string for bill you generate has all components in a different line. (Don’t forget to add “\n” after each line of billing) 39 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/PolyMorphism/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/PolyMorphism/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/PolyMorphism/Example.java: -------------------------------------------------------------------------------- 1 | class Vehicle { 2 | String color; 3 | int seats; 4 | 5 | public void Vehiclehonk(){ 6 | System.out.println("Honking from the vehicle class"); 7 | } 8 | 9 | public int add(int a, int b){ 10 | return a+b; 11 | } 12 | } 13 | 14 | class Car extends Vehicle { 15 | int engine=47; 16 | 17 | // method overLoading 18 | public void Vehiclehonk(int a){ 19 | System.out.println("Honking from the Car class"); 20 | } 21 | 22 | @Override // method overRiding 23 | public int add(int a, int b){ 24 | return a + 1 + b + 1; 25 | } 26 | } 27 | 28 | public class Example { 29 | public static void main(String[] args) { 30 | Car c1 = new Car(); 31 | c1.Vehiclehonk(5); // this is visible at compile time 32 | 33 | // upcasting 34 | // Vehicle v = new Vehicle(); 35 | Vehicle v = new Car(); 36 | v.add(2,3); // this is resolved at run time 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/PolyMorphism/Main.java: -------------------------------------------------------------------------------- 1 | class Vehicle { 2 | String color; 3 | int seats; 4 | 5 | public void Vehiclehonk(){ 6 | System.out.println("Honking from the vehicle class"); 7 | } 8 | 9 | public int add(int a, int b){ 10 | return a+b; 11 | } 12 | } 13 | 14 | class Car extends Vehicle { 15 | int engine=47; 16 | 17 | // method overLoading 18 | public void Vehiclehonk(int a){ 19 | System.out.println("Honking from the Car class"); 20 | } 21 | 22 | @Override // method overRiding 23 | public int add(int a, int b){ 24 | return a + 1 + b + 1; 25 | } 26 | } 27 | 28 | class Hyundai extends Car { 29 | int model_number; 30 | 31 | // method overLoading 32 | public void Vehiclehonk(String a){ 33 | System.out.println("Honking from Hyundai class"); 34 | } 35 | } 36 | 37 | 38 | public class Main { 39 | public static void main(String[] args) { 40 | Hyundai h1 = new Hyundai(); 41 | // h1.Vehiclehonk(); 42 | 43 | Car c1 = new Car(); 44 | System.out.println(h1.add(2, 1)); 45 | 46 | // Vehicle v = new Vehicle(); 47 | // System.out.println(v.add(2,1)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/PolyMorphism/MethodOverriding.java: -------------------------------------------------------------------------------- 1 | class Bank { 2 | public int rateOfInterest(){ 3 | return 7; 4 | } 5 | } 6 | class HDFC extends Bank { 7 | public int rateOfInterest(){ 8 | return 5; 9 | } 10 | } 11 | class SBI extends Bank { 12 | public int rateOfInterest(){ 13 | return 6; 14 | } 15 | } 16 | class Kotak extends Bank { 17 | public int rateOfInterest(){ 18 | return 8; 19 | } 20 | } 21 | 22 | class Parent { 23 | public static void display(){ // its binding at compile time -> static binding 24 | System.out.println("Displaying from the parent class"); 25 | } 26 | 27 | public int nonStaticAdd(int a, int b){ 28 | return a+b; 29 | } 30 | } 31 | 32 | class Child extends Parent { 33 | public static void display(){ 34 | System.out.println("Displaying from child class"); 35 | } 36 | 37 | public int nonStaticAdd(int a, int b){ 38 | return a - b; 39 | } 40 | } 41 | 42 | public class MethodOverriding { 43 | public static void main(String[] args) { 44 | Parent p = new Child(); 45 | System.out.println(p.nonStaticAdd(2,3)); 46 | p.display(); 47 | // Bank b; 48 | 49 | // b = new Bank(); 50 | // System.out.println(b.rateOfInterest()); 51 | 52 | // b = new HDFC(); // up casting, dynamic binding, late binding 53 | // System.out.println(b.rateOfInterest()); 54 | 55 | // b = new SBI(); 56 | // System.out.println(b.rateOfInterest()); 57 | 58 | // b=new Kotak(); 59 | // System.out.println(b.rateOfInterest()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Static Keyword/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/OOPS/Static Keyword/.DS_Store -------------------------------------------------------------------------------- /Module 2 January/OOPS/Static Keyword/Example.java: -------------------------------------------------------------------------------- 1 | class Car { 2 | String color; 3 | static int count=34; 4 | 5 | public static void fun(){ 6 | // color = "red"; // this is not allowed 7 | // fun2(); not allowed 8 | System.out.println("Static function is called"); 9 | count = 39; 10 | } 11 | 12 | public void fun2(){ 13 | color = "red"; 14 | count = 44; 15 | } 16 | } 17 | 18 | public class Example { 19 | public static void main(String[] args) { 20 | Car c1 = new Car(); 21 | c1.color = "blue"; 22 | c1.fun2(); 23 | 24 | System.out.print(c1); 25 | 26 | // Car.fun2(); 27 | 28 | // Car.fun(); 29 | Car.count = 56; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Static Keyword/Example2.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | class Student { 4 | String name ; 5 | int age ; 6 | int roll_no; 7 | 8 | public Student(String name, int age, int roll_no){ 9 | this.name = name; 10 | this.age = age; 11 | this.roll_no = roll_no; 12 | } 13 | 14 | public void fun(){ 15 | System.out.println("I am "+name); 16 | } 17 | 18 | @Override // refer polymorphism 19 | public String toString(){ 20 | // return "bvd"; 21 | return "Name of the student is " + name + " with an age of " + age + " and a roll number " + roll_no; 22 | // return "Return this statement"; 23 | } 24 | } 25 | 26 | public class Example2 { 27 | public static void main(String[] args) { 28 | Student s1 = new Student("Sanket", 23, 1); 29 | Student s2 = new Student("Rajesh", 19, 11); 30 | Student s3 = new Student("Mahesh", 21, 49); 31 | 32 | System.out.println(s3); 33 | System.out.println(s1); 34 | 35 | // int[] arr = new int[5]; 36 | // System.out.println(arr); 37 | 38 | // ArrayList al = new ArrayList<>(); 39 | // al.add(5); 40 | 41 | // System.out.println(al); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Static Keyword/Main.java: -------------------------------------------------------------------------------- 1 | class Car { 2 | String color; 3 | int model_number; 4 | static String car_company="Mahindra"; 5 | static int count = 0; 6 | 7 | public Car(){ 8 | count++; 9 | } 10 | 11 | public void fun2(){ 12 | color = "red"; 13 | System.out.println("Having fun!!!!!!!!!!"); 14 | } 15 | 16 | public static void fun(){ 17 | // color="red"; // not possible 18 | count=56; 19 | // fun2(); 20 | System.out.println("Having fun!!!!!!!!!!"); 21 | } 22 | } 23 | 24 | public class Main { 25 | class Student { //why we need to define this class as static 26 | int a; 27 | } 28 | 29 | public void fun(){ 30 | Student s1 = new Student(); // this is possible 31 | } 32 | public static void main(String[] args) { 33 | // Student s1 = new Student(); // this is not possible 34 | 35 | Car c1 = new Car(); // and this is possible 36 | c1.color= "blue"; 37 | 38 | Car c2 = new Car(); 39 | c2.color = "Silver dust"; 40 | 41 | Car c3 = new Car(); 42 | c1.car_company = "Accio"; 43 | c1.color="Red"; 44 | 45 | // c3.count = 45; 46 | 47 | System.out.println(c2.car_company); 48 | System.out.println(c2.count); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Module 2 January/OOPS/Wrapper Classes/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | int a = 5; // primitive data type 4 | 5 | // Integer i = new Integer(a); // boxing -> wrapping 6 | 7 | Integer i = a; // autoboxing 8 | 9 | Integer obj = new Integer(100); 10 | 11 | // int ab = obj.intValue(); // unboxing -> unwrapping 12 | int ab = obj; // autoUnboxing 13 | 14 | // why? 15 | String s = "123"; 16 | int b = Integer.parseInt(s); 17 | 18 | // Wrapper Classses 19 | // int -> Integer; 20 | // char -> Character; 21 | // long -> Long; 22 | // boolean -> Boolean; 23 | // float -> Float; 24 | // byte -> Byte; 25 | // double -> Double; 26 | // short-> Short; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Module 2 January/Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/Recursion.pdf -------------------------------------------------------------------------------- /Module 2 January/Recursion/ArrayListExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/Recursion/ArrayListExample.class -------------------------------------------------------------------------------- /Module 2 January/Recursion/ArrayListExample.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class ArrayListExample { 4 | public static void main(String[] args) { 5 | ArrayList al = new ArrayList<>(); 6 | 7 | al.add("abc"); 8 | al.add("def"); 9 | al.add("abcd"); 10 | 11 | System.out.println(al); 12 | 13 | al.remove(1); 14 | System.out.println(al); 15 | 16 | al.set(1,"Accio"); 17 | System.out.println(al); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Module 2 January/Recursion/MergeSort and QuickSort/MergeSort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/Recursion/MergeSort and QuickSort/MergeSort.class -------------------------------------------------------------------------------- /Module 2 January/Recursion/MergeSort and QuickSort/MergeSort.java: -------------------------------------------------------------------------------- 1 | class MergeSort { 2 | public static int[] merge2SortedArrays(int[] arr1, int[] arr2){ 3 | int n = arr1.length; 4 | int m = arr2.length; 5 | 6 | int[] ans = new int[n+m]; 7 | 8 | int i=0; 9 | int j=0; 10 | int k=0; 11 | int ei1 = n-1; // ei for arr1 12 | int ei2 = m-1; // ei for arr2 13 | 14 | while(i<=ei1 && j<=ei2){ 15 | if(arr1[i] < arr2[j]){ 16 | ans[k] = arr1[i]; 17 | i++; 18 | } else { 19 | ans[k] = arr2[j]; 20 | j++; 21 | } 22 | k++; 23 | } 24 | 25 | while(i<=ei1){ 26 | ans[k] = arr1[i]; 27 | i++; 28 | k++; 29 | } 30 | 31 | while(j<=ei2){ 32 | ans[k] = arr2[j]; 33 | j++; 34 | k++; 35 | } 36 | 37 | return ans; 38 | } 39 | 40 | public static void mergeSortedArrays(int[] arr, int si, int mid, int ei){ 41 | int i = si; 42 | int j = mid + 1; 43 | int k = 0; 44 | int ei1 = mid; 45 | int ei2 = ei; 46 | 47 | int[] ans = new int[ei - si + 1]; 48 | 49 | while(i<=ei1 && j<=ei2){ 50 | if(arr[i] < arr[j]){ 51 | ans[k] = arr[i]; 52 | i++; 53 | } else { 54 | ans[k] = arr[j]; 55 | j++; 56 | } 57 | k++; 58 | } 59 | 60 | while(i<=ei1){ 61 | ans[k] = arr[i]; 62 | i++; 63 | k++; 64 | } 65 | 66 | while(j<=ei2){ 67 | ans[k] = arr[j]; 68 | j++; 69 | k++; 70 | } 71 | 72 | 73 | k=0; 74 | for(int idx = si; idx<=ei; idx++,k++){ 75 | arr[idx] = ans[k]; 76 | } 77 | } 78 | 79 | public static void mergeSort(int[] arr, int si, int ei){ 80 | if(si==ei){ 81 | return; 82 | } 83 | 84 | int mid = (si + ei)/2; 85 | 86 | mergeSort(arr, si, mid); 87 | mergeSort(arr, mid+1, ei); 88 | mergeSortedArrays(arr,si,mid,ei); 89 | } 90 | public static void main(String[] args) { 91 | // int[] arr1 = {1,2,13,19,20,23,24}; 92 | // int[] arr2 = {3,4,11,21}; 93 | 94 | // int[] ans = merge2SortedArrays(arr1, arr2); 95 | // for(int i=0; i=ei){ 42 | return; 43 | } 44 | int pivot = arr[ei]; 45 | 46 | int pidx = partitionPivot(arr, pivot, si, ei); 47 | quickSort(arr, si, pidx - 1); 48 | quickSort(arr, pidx + 1, ei); 49 | } 50 | public static void main(String[] args) { 51 | int[] arr = {9,12,5,10,14,3,10}; 52 | 53 | partition(arr, 10); 54 | System.out.println(Arrays.toString(arr)); 55 | // quickSort(arr, 0, arr.length-1); 56 | // for(int i=0; iei){ 92 | return true; 93 | } 94 | 95 | if(arr[si]!=arr[ei]){ 96 | return false; 97 | } 98 | 99 | boolean ans = isPalindromic(arr, si + 1, ei - 1); 100 | return ans; 101 | } 102 | public static void main(String[] args) { 103 | int[] arr = {9,3,7,3,3,5,3,6}; 104 | int[] ans = allIndices(arr, 0, 3, 0); 105 | 106 | for(int i=0; i=n || j>=m){ 5 | return 0; 6 | } 7 | if(i==n-1 && j==m-1){ 8 | return 1; 9 | } 10 | int hpaths = mazePaths(i, j+1, n, m); 11 | int vpaths = mazePaths(i+1, j, n, m); 12 | 13 | int allPaths = hpaths + vpaths; 14 | return allPaths; 15 | } 16 | 17 | // number of stair paths ========================================== 18 | public static int numberOfPaths(int n){ 19 | if(n<0){ 20 | return 0; 21 | } 22 | if(n==0){ 23 | return 1; 24 | } 25 | 26 | int numberOfPathsAfterOneStep = numberOfPaths(n-1); 27 | int numberOfPathsAfterTwoStep = numberOfPaths(n-2); 28 | int numberOfPathsAfterOneThreeStep = numberOfPaths(n-3); 29 | 30 | int numberOfPaths = numberOfPathsAfterOneStep + numberOfPathsAfterTwoStep + numberOfPathsAfterOneThreeStep; 31 | 32 | return numberOfPaths; 33 | } 34 | public static void main(String[] args) { 35 | System.out.println(numberOfPaths(4)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Module 2 January/Recursion/Recursion with Strings/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2 January/Recursion/Recursion with Strings/Main.class -------------------------------------------------------------------------------- /Module 2/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/.DS_Store -------------------------------------------------------------------------------- /Module 2/Linked List .pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/Linked List .pdf -------------------------------------------------------------------------------- /Module 2/LinkedList/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/LinkedList/.DS_Store -------------------------------------------------------------------------------- /Module 2/LinkedList/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/LinkedList/Introduction/Main.class -------------------------------------------------------------------------------- /Module 2/LinkedList/Introduction/Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/LinkedList/Introduction/Node.class -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/07_11_2022/Car.class -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/CounterExample.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | static int count=0; 4 | 5 | public Student(String n){ 6 | name=n; 7 | count=count+1; 8 | } 9 | 10 | public static void Bunk(){ 11 | System.out.println("Bunking the classes"); 12 | } 13 | } 14 | public class CounterExample { 15 | public static void main(String[] args) { 16 | Student Pratik=new Student("Pratik"); 17 | System.out.println(Pratik.count); 18 | 19 | Student a=new Student("a"); 20 | System.out.println(Pratik.count); 21 | 22 | Student b=new Student("b"); 23 | System.out.println(Pratik.count); 24 | 25 | Student c=new Student("c"); 26 | System.out.println(c.count); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/Hyundai.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/07_11_2022/Hyundai.class -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/Inheritance.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/07_11_2022/Inheritance.class -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/Inheritance.java: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Vechile { 4 | int no_of_wheels; 5 | String color="Blue"; 6 | 7 | public Vechile(){ 8 | System.out.println("Vechile constructor is called"); 9 | } 10 | 11 | public void makeSound(){ 12 | System.out.println("Making Vehicle sound"); 13 | } 14 | } 15 | 16 | class Car extends Vechile { 17 | int model_number; 18 | 19 | public Car(){ 20 | System.out.println("Car constructor is called"); 21 | } 22 | 23 | public void carSound(){ 24 | System.out.println("Making car sound"); 25 | } 26 | } 27 | 28 | class Hyundai extends Car { 29 | String name="Accio"; 30 | 31 | public Hyundai(){ 32 | System.out.println("Hyundai constructor is called"); 33 | } 34 | 35 | public String toString(){ 36 | return name; 37 | } 38 | } 39 | 40 | public class Inheritance{ 41 | public static void main(String[] args) { 42 | Hyundai h1 = new Hyundai(); 43 | System.out.println(h1); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/MultiLevelInheritance.java: -------------------------------------------------------------------------------- 1 | class GrandParent { 2 | public GrandParent(){ 3 | System.out.println("GrandParent constructor"); 4 | } 5 | } 6 | 7 | class Parent extends GrandParent { 8 | public Parent(){ 9 | System.out.println("Parent constructor is called"); 10 | } 11 | } 12 | 13 | class Child extends Parent { 14 | public Child(){ 15 | System.out.println("Child constructor is called"); 16 | } 17 | } 18 | 19 | public class MultiLevelInheritance 20 | { 21 | public static void main(String[] args) { 22 | Child c1 = new Child(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/StaticExample.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | static String organisation="Accio"; 4 | int roll_number; 5 | 6 | public Student(String n, int r){ 7 | name=n; 8 | roll_number=r; 9 | } 10 | } 11 | 12 | class Car { 13 | int model_number; 14 | String owner_name; 15 | static String car_company="Hyundai"; 16 | } 17 | 18 | public class StaticExample 19 | { 20 | public static void main(String[] args) { 21 | Student s1=new Student("pratik",1); 22 | Student s2=new Student("Other",2); 23 | Student s3=new Student("Aakash",3); 24 | 25 | Student s4=new Student("Harsh",4); 26 | 27 | s2.organisation = "GFG"; 28 | System.out.println(s4.organisation); 29 | System.out.println(s1.organisation); 30 | 31 | Car c1=new Car(); 32 | c1.model_number=1; 33 | 34 | Car c2=new Car(); 35 | c2.model_number=2; 36 | 37 | 38 | Car c3=new Car(); 39 | c3.model_number=3; 40 | 41 | System.out.println(c1.car_company); 42 | 43 | c1.car_company="Rolls Royce"; 44 | 45 | System.out.println(c3.car_company); 46 | System.out.println(c1.car_company); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/StaticMethods.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | static int count=0; 4 | 5 | public Student(String n){ 6 | name=n; 7 | count=count+1; 8 | } 9 | 10 | public static void Bunk(){ 11 | count=56; 12 | System.out.println("Bunking the classes"); 13 | } 14 | 15 | public void dontBunk(){ 16 | System.out.println("Still bunking the classes"); 17 | } 18 | } 19 | 20 | public class StaticMethods { 21 | public static void main(String[] args) { 22 | // Student s1=new Student("Pratik"); 23 | // s1.dontBunk(); 24 | 25 | Student.Bunk(); 26 | System.out.println(Student.count); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Module 2/OOPS/07_11_2022/Vechile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/07_11_2022/Vechile.class -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Accio.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/08_11_2022/Accio.class -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Accio.java: -------------------------------------------------------------------------------- 1 | public class Accio { 2 | public static void main(String[] args) { 3 | String a="Pratik"; 4 | String b="job"; 5 | 6 | System.out.println(a); 7 | System.out.println(b); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/ConstructorChaining.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name="Pratik"; 3 | int roll_number=1; 4 | int class_number=12; 5 | 6 | // parametrized constructors 7 | //cons 1 8 | public Student(){ 9 | 10 | } 11 | 12 | public Student(String n){ // cons2 13 | System.out.println("Constructor 2 is called"); 14 | this.name=n; 15 | } 16 | 17 | public Student(String n, int rn){ // cons3 18 | this(n); 19 | System.out.println("Constructor 3 is called"); 20 | this.roll_number=rn; 21 | } 22 | 23 | public Student(String n, int rn, int cn){ // cons4 24 | this(n,rn); // calling 3rd constructor 25 | System.out.println("Constructor 4 is called"); 26 | this.class_number=cn; 27 | } 28 | 29 | } 30 | 31 | public class ConstructorChaining { 32 | public static void main(String[] args) { 33 | Student s1=new Student("Accio",10); 34 | 35 | // s1.doSomething(123); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/ConstructorChaining2.java: -------------------------------------------------------------------------------- 1 | class Vechile { 2 | int no_of_wheels; 3 | String color="Blue"; 4 | 5 | public Vechile(int now, String c){ 6 | this.no_of_wheels=now; 7 | this.color=c; 8 | } 9 | } 10 | 11 | class Car extends Vechile { 12 | int model_number; 13 | 14 | public Car(int mn, int now, String c){ 15 | super(now,c); 16 | this.model_number=mn; 17 | } 18 | } 19 | 20 | public class Main { 21 | public static void main(String[] args) { 22 | Car c1 = new Car(15,4,"Black"); 23 | 24 | System.out.println(c1.model_number); 25 | System.out.println(c1.no_of_wheels); 26 | System.out.println(c1.color); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/08_11_2022/Example.class -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Example.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | int roll_number=1; 4 | int class_number=12; 5 | 6 | public void print(int roll_number){ 7 | 8 | System.out.println(roll_number); 9 | } 10 | } 11 | 12 | public class Example { 13 | public static void main(String[] args) { 14 | Student s1=new Student(); 15 | s1.print(15); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/08_11_2022/Main.class -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | int a=10; 4 | 5 | System.out.println(a); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/PolyMorphism/Example.java: -------------------------------------------------------------------------------- 1 | class Bank { 2 | public int rateOfInterest(){ 3 | return 5; 4 | } 5 | } 6 | 7 | class SBI extends Bank { 8 | public int rateOfInterest(){ 9 | return 3; 10 | } 11 | } 12 | 13 | class HDFC extends Bank { 14 | public int rateOfInterest(){ 15 | return 7; 16 | } 17 | } 18 | 19 | class Icici extends Bank { 20 | public int rateOfInterest(){ 21 | return 4; 22 | } 23 | } 24 | 25 | public class Example { 26 | public static void main(String[] args) { 27 | Bank b; // at compile time "b" is of Bank type 28 | // upcasting 29 | b=new SBI(); // at run time, when i allot space in Heap, "b" is actually of "SBI" type ==> dynamic binding, late Binding 30 | System.out.println("Rate of interest is "+b.rateOfInterest()); 31 | 32 | b=new Icici(); 33 | System.out.println("Rate of interest is "+b.rateOfInterest()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/PolyMorphism/MethodOverRiding.java: -------------------------------------------------------------------------------- 1 | class Vechile { 2 | int no_of_wheels; 3 | String color="Blue"; 4 | 5 | public Vechile(int now, String c){ 6 | this.no_of_wheels=now; 7 | this.color=c; 8 | } 9 | 10 | public void honk(){ 11 | System.out.println("Honking from the parent class"); 12 | } 13 | } 14 | 15 | class Car extends Vechile { 16 | int model_number; 17 | 18 | public Car(int mn, int now, String c){ 19 | super(now,c); 20 | this.model_number=mn; 21 | } 22 | 23 | @Override 24 | public void honk(){ 25 | System.out.println("Honking from child class"); 26 | } 27 | } 28 | 29 | public class Main { 30 | public static void main(String[] args) { 31 | Car c1 = new Car(15,4,"Black"); 32 | 33 | // System.out.println(c1.model_number); 34 | // System.out.println(c1.no_of_wheels); 35 | // System.out.println(c1.color); 36 | 37 | c1.honk(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/PolyMorphism/MethodOverloading.java: -------------------------------------------------------------------------------- 1 | class Vechile { 2 | int no_of_wheels; 3 | String color="Blue"; 4 | 5 | public void Honk(){ 6 | System.out.println("Honking with no parameters"); 7 | } 8 | 9 | public void Honk(int a, int b){ 10 | System.out.println("2 params"); 11 | } 12 | 13 | public void Honk(String a, String b){ 14 | System.out.println("peee peee "+a); 15 | } 16 | 17 | public void Honk(String s, int b){ 18 | System.out.println("pee pee but different "+s); 19 | } 20 | 21 | public void Honk(int b, String s){ 22 | System.out.println("Trying"); 23 | } 24 | } 25 | 26 | public class Main { 27 | public static void main(String[] args) { 28 | Vechile v1=new Vechile(); 29 | 30 | v1.Honk("Accio",2); 31 | v1.Honk(2,"Accio"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/08_11_2022/Student.class -------------------------------------------------------------------------------- /Module 2/OOPS/08_11_2022/SuperKeyword.java: -------------------------------------------------------------------------------- 1 | class Vechile { 2 | int no_of_wheels; 3 | String color="Blue"; 4 | 5 | public void HonkVechile(){ 6 | System.out.println("parent sound"); 7 | } 8 | } 9 | 10 | class Car extends Vechile { 11 | int model_number; 12 | 13 | public void HonkVechile(){ 14 | System.out.println("Child sound"); 15 | } 16 | 17 | public void HonkCar(){ // this -> my own HonkVechile(13th line) , super-> parent's function(5th line) 18 | super.HonkVechile(); 19 | } 20 | } 21 | 22 | public class Main { 23 | public static void main(String[] args) { 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/A.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/A.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/A/File1.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | protected String name; 3 | } 4 | 5 | public class File1 { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Abstraction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Abstraction.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Abstraction.java: -------------------------------------------------------------------------------- 1 | abstract class Student { 2 | String name; 3 | 4 | public void print(){ 5 | System.out.println("Printing something"); 6 | } 7 | 8 | abstract void printAbstract(); 9 | abstract void printNothing(); 10 | } 11 | 12 | class Child extends Student { 13 | public void printAbstract(){ 14 | System.out.println("Printing abstract"); 15 | } 16 | 17 | public void printNothing(){ 18 | System.out.println("Printing nothing"); 19 | } 20 | } 21 | 22 | public class Abstraction { 23 | public static void main(String[] args) { 24 | Child c1 =new Child(); 25 | Node address 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/AbstractionExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/AbstractionExample.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/AbstractionExample.java: -------------------------------------------------------------------------------- 1 | abstract class Shape { 2 | public void saySomething(){ 3 | System.out.println("hjbxjbx"); 4 | } 5 | abstract void draw(); 6 | } 7 | 8 | class Circle extends Shape { 9 | public void draw(){ 10 | System.out.println("Drawing circle"); 11 | } 12 | } 13 | 14 | class Rectangle extends Shape { 15 | public void draw(){ 16 | System.out.println("Drawing rectangle"); 17 | } 18 | } 19 | 20 | public class AbstractionExample { 21 | public static void main(String[] args) { 22 | // upcasting 23 | Shape s= new Circle(); 24 | s.draw(); 25 | 26 | s=new Rectangle(); 27 | s.draw(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/B.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/B.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/B/File2.java: -------------------------------------------------------------------------------- 1 | public class File2 { 2 | public static void main(String[] args) { 3 | Student s1=new Student(); 4 | System.out.println(s1.name); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Car.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Child.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Child.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Circle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Circle.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Encapsulation.java: -------------------------------------------------------------------------------- 1 | final class Employee { 2 | String name; 3 | private int salary = 100000; 4 | 5 | public Employee(String n){ 6 | this.name=n; 7 | } 8 | 9 | // setters 10 | public void setSalary(int new_salary){ 11 | if(new_salary > 3000){ 12 | this.salary = 0; 13 | } else { 14 | this.salary = new_salary; 15 | } 16 | } 17 | 18 | // getters 19 | public int getSalary(){ 20 | return this.salary; 21 | } 22 | } 23 | 24 | 25 | public class Main { 26 | public static void main(String[] args) { 27 | Employee Pratik = new Employee("Pratik"); 28 | 29 | Pratik.setSalary(10000000); 30 | System.out.println(Pratik.getSalary()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Final.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | final String name="Accio"; 3 | static int a=5; 4 | 5 | public void changeName(){ 6 | name = "Pratik"; // error -> The final field Student.name cannot be assigned 7 | a++; 8 | } 9 | } 10 | 11 | public class Main { 12 | public static void main(String[] args) { 13 | Student s1=new Student(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/InterfaceExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/InterfaceExample.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/InterfaceExample.java: -------------------------------------------------------------------------------- 1 | interface Shape { 2 | public void draw(); 3 | public void area(); 4 | } 5 | 6 | class Circle implements Shape { 7 | public void draw(){ 8 | System.out.println("Drawing circle"); 9 | } 10 | 11 | public void area(){ 12 | System.out.println("Circle area"); 13 | } 14 | } 15 | 16 | class Rectangle implements Shape { 17 | public void draw(){ 18 | System.out.println("Drawing Rectangle"); 19 | } 20 | 21 | public void area(){ 22 | System.out.println("Rectangle area"); 23 | } 24 | } 25 | 26 | public class InterfaceExample { 27 | public static void main(String[] args) { 28 | Rectangle r = new Rectangle(); 29 | r.area(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/MultipleInheritance.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/MultipleInheritance.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/MultipleInheritance.java: -------------------------------------------------------------------------------- 1 | interface A { 2 | public void honk(); 3 | } 4 | 5 | interface B { 6 | public void honk(); 7 | } 8 | 9 | class Car implements A,B { 10 | public void honk(){ 11 | System.out.println("Honking"); 12 | } 13 | } 14 | 15 | public class MultipleInheritance { 16 | public static void main(String[] args) { 17 | Car c1 = new Car(); 18 | c1.honk(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Rectangle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Rectangle.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Shape.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Shape.class -------------------------------------------------------------------------------- /Module 2/OOPS/09_11_2022/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/09_11_2022/Student.class -------------------------------------------------------------------------------- /Module 2/OOPS/Class 1/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/Class 1/Car.class -------------------------------------------------------------------------------- /Module 2/OOPS/Class 1/OOP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/Class 1/OOP.class -------------------------------------------------------------------------------- /Module 2/OOPS/Class 1/OOP.java: -------------------------------------------------------------------------------- 1 | // blueprint for student 2 | class Student { 3 | String name; 4 | int roll_number; // class property -> rnOne 5 | int class_number; 6 | 7 | // default constructor ========================== 8 | public Student(){ 9 | System.out.println("Constructor is called"); 10 | name="Accio"; 11 | roll_number=1; 12 | class_number=10; 13 | } 14 | 15 | // parametrized constructor 16 | public Student(String a, int rollNo, int classNo){ 17 | System.out.println("constructor 2 is called"); 18 | this.name=a; 19 | this.roll_number=rollNo; // value of variable at 4th line is being set 20 | this.class_number=classNo; 21 | } 22 | 23 | public void dontMakeNoise(){ 24 | System.out.println("Shh!!!"); 25 | } 26 | 27 | public void makeNoise(){ 28 | System.out.println("We are making noise!!!!!"); 29 | dontMakeNoise(); 30 | } 31 | } 32 | 33 | 34 | public class OOP { 35 | 36 | public static void main(String[] args) { 37 | Student s1 = new Student(); // it will call the construtcor automatically, it will create heap memory 38 | Student s2= new Student("pratik",2,10); 39 | 40 | s1.makeNoise(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Module 2/OOPS/Class 1/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPS/Class 1/Student.class -------------------------------------------------------------------------------- /Module 2/OOPs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/OOPs.pdf -------------------------------------------------------------------------------- /Module 2/Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/Recursion.pdf -------------------------------------------------------------------------------- /Module 2/Recursion/Class 1/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void printSomething(){ 3 | System.out.println("Hi!!"); 4 | 5 | int a=5; 6 | a++; 7 | a--; 8 | 9 | a=11; 10 | } 11 | 12 | public static int sum(int a, int b){ 13 | printSomething(); 14 | 15 | int sum = a + b; 16 | return sum; 17 | } 18 | 19 | public static void main(String[] args) { 20 | int a=2; 21 | int b=3; 22 | 23 | int ans=sum(a, b); 24 | System.out.println(ans); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Module 2/Recursion/Class 1/PrintDecreasing.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/Recursion/Class 1/PrintDecreasing.class -------------------------------------------------------------------------------- /Module 2/Recursion/Class 1/PrintDecreasing.java: -------------------------------------------------------------------------------- 1 | public class PrintDecreasing { 2 | // print decreasing 3 | public static void pd(int n){ 4 | if(n==0){ 5 | return; 6 | } 7 | 8 | System.out.println(n); 9 | pd(n-1); 10 | } 11 | 12 | // print increasing 13 | public static void PI(int n){ 14 | if(n==0){ 15 | return; 16 | } 17 | 18 | PI(n-1); 19 | System.out.println(n); 20 | } 21 | 22 | // print decreasing then increasing 23 | public static void PDI(int n){ 24 | if(n==0){ 25 | return; 26 | } 27 | 28 | System.out.println(n); 29 | PDI(n-1); 30 | System.out.println(n); 31 | } 32 | 33 | // factorial =================================== 34 | public static int fac(int n){ 35 | if(n==1) return 1; 36 | 37 | int sAns = fac(n-1); 38 | int ans= n * sAns; 39 | 40 | return ans; 41 | } 42 | public static void main(String[] args) { 43 | // pd(5); 44 | PI(5); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Module 2/Recursion/Class 2/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 2/Recursion/Class 2/Main.class -------------------------------------------------------------------------------- /Module 2/Recursion/Class 2/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | // power 3 | public static int power(int x, int n){ 4 | if(n==0){ 5 | return 1; 6 | } 7 | 8 | int sAns = power(x,n-1); 9 | int ans = x * sAns; 10 | 11 | return ans; 12 | } 13 | 14 | // power logarithmic 15 | public static int power_log(int x, int n){ 16 | if(n==0){ 17 | return 1; 18 | } 19 | 20 | int sAns = power_log(x, n/2); 21 | 22 | int ans=0; 23 | if(n%2==0){ // if n is even 24 | ans = sAns * sAns; 25 | } else { // if n is odd 26 | ans = sAns * sAns * x; 27 | } 28 | 29 | return ans; 30 | } 31 | 32 | // sum of first n natural numbers 33 | public static int sum_natural(int n){ 34 | if(n==0){ 35 | return 0; 36 | } 37 | 38 | int sAns = sum_natural(n-1); 39 | int ans = n + sAns; 40 | 41 | return ans; 42 | } 43 | 44 | // print array recursively ======================================= 45 | public static void printArray(int idx, int[] arr){ 46 | if(idx == arr.length){ 47 | return; 48 | } 49 | 50 | System.out.println(arr[idx]); 51 | printArray(idx+1, arr); 52 | } 53 | 54 | public static void main(String[] args) { 55 | // int ans = power(2, 4); 56 | 57 | // System.out.println(ans); 58 | 59 | int[] arr ={7,3,2,0,9}; 60 | printArray(0, arr); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Module 2/Recursion/Class 3, Recursion with Arrays /Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | // print array recursively ======================================= 3 | public static void printArray(int idx, int[] arr){ 4 | if(idx == arr.length){ 5 | return; 6 | } 7 | 8 | System.out.println(arr[idx]); 9 | printArray(idx+1, arr); 10 | } 11 | 12 | // print array in reverse recursively ==================================== 13 | public static void printArrayReverse(int idx, int[] arr){ 14 | if(idx==arr.length){ 15 | return; 16 | } 17 | 18 | printArrayReverse(idx+1, arr); 19 | System.out.println(arr[idx]); 20 | } 21 | 22 | public static void fun(int i, int a){ 23 | if(i>4){ 24 | return; 25 | } 26 | 27 | a = a + 1; 28 | fun(i+1,a); 29 | } 30 | 31 | public static int maxOfArray(int idx, int[] arr){ 32 | if(idx==arr.length){ 33 | return 0; 34 | } 35 | 36 | int sAns = maxOfArray(idx+1, arr); 37 | int ans=Math.max(arr[idx],sAns); 38 | 39 | return ans; 40 | }; 41 | 42 | public static int maxOfArray2(int idx, int[] arr){ 43 | if(idx==arr.length){ 44 | return 0; 45 | } 46 | 47 | int sAns = maxOfArray2(idx+1, arr); 48 | if(sAns > arr[idx]){ 49 | return sAns; 50 | } else { 51 | return arr[idx]; 52 | } 53 | }; 54 | 55 | public static int firstIndex(int idx, int[] arr, int tar){ 56 | if(idx == arr.length){ 57 | return -1; 58 | } 59 | 60 | int sAns = firstIndex(idx+1, arr, tar); 61 | int ans = 0; 62 | if(arr[idx] == tar){ 63 | ans = idx; 64 | } else { 65 | ans = sAns; 66 | } 67 | 68 | return ans; 69 | } 70 | 71 | public static int lastIndex(int idx, int[] arr, int tar){ 72 | if(idx == arr.length){ 73 | return -1; 74 | } 75 | 76 | int sAns = lastIndex(idx+1, arr, tar); 77 | int ans=0; 78 | 79 | if(sAns == -1){ 80 | if(arr[idx]==tar){ 81 | ans = idx; 82 | } else { 83 | ans = -1; 84 | } 85 | } else { 86 | ans = sAns; 87 | } 88 | 89 | return ans; 90 | } 91 | 92 | public static int[] allIndices(int idx, int[] arr, int tar, int count){ 93 | if(idx == arr.length){ 94 | int[] ba = new int[count]; 95 | return ba; 96 | } 97 | 98 | int[] ans; 99 | if(arr[idx]==tar){ 100 | ans = allIndices(idx+1, arr, tar, count+1); 101 | } else { 102 | ans = allIndices(idx+1, arr, tar, count); 103 | } 104 | 105 | if(arr[idx] == tar){ 106 | ans[count] = idx; 107 | } 108 | 109 | return ans; 110 | } 111 | 112 | public static void main(String[] args) { 113 | int[] arr ={7,3,3,0,3,4}; 114 | int[] ans = allIndices(0, arr,3,0); 115 | 116 | for(int i=0; i getSubsequences(String str){ 6 | if(str.length()==0){ 7 | ArrayList ba = new ArrayList<>(); 8 | ba.add(""); 9 | return ba; 10 | } 11 | 12 | char first_char = str.charAt(0); 13 | String ss = str.substring(1); // small string 14 | 15 | ArrayList sAns = getSubsequences(ss); // faith 16 | 17 | ArrayList ans = new ArrayList<>(); 18 | 19 | // copy from sAns 20 | for(int i=0; i subs = getSubsequences("abc"); 51 | System.out.println(subs); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Module 2/Recursion/Class 4/robHouse.java: -------------------------------------------------------------------------------- 1 | public class robHouse { 2 | public static int robHouse(int idx, int end, int[] arr){ 3 | if(idx>end){ 4 | return 0; 5 | } 6 | 7 | // rob current idx 8 | int rob = robHouse(idx+2,end,arr) + arr[idx]; 9 | 10 | // skip current idx 11 | int skip = robHouse(idx+1, end, arr); 12 | 13 | int ans = Math.max(rob,skip); 14 | return ans; 15 | } 16 | 17 | public static void main (String[] args) throws java.lang.Exception 18 | { 19 | Scanner scn = new Scanner(System.in); 20 | int n=scn.nextInt(); 21 | 22 | int[] arr=new int[n]; 23 | for(int i=0; i getKPC(String ques){ 7 | if(ques.length()==0){ 8 | ArrayList ba=new ArrayList<>(); 9 | ba.add(""); 10 | return ba; 11 | } 12 | 13 | char first_char = ques.charAt(0); 14 | String ss = ques.substring(1); 15 | ArrayList sans = getKPC(ss); 16 | 17 | int idx = first_char - '0'; 18 | 19 | String str = sarr[idx]; // tu 20 | 21 | ArrayList ans = new ArrayList<>(); 22 | for(int i=0; i ans = getKPC(ques); 39 | 40 | for(int i=0; itar){ 4 | return; 5 | } 6 | if(idx == arr.length){ 7 | if(csum==tar){ 8 | System.out.println(asf); 9 | } 10 | return; 11 | } 12 | 13 | // include 14 | combination_oneCoin(arr, idx+1, tar, csum+arr[idx], asf+arr[idx]+","); 15 | 16 | // not include 17 | combination_oneCoin(arr, idx+1, tar, csum, asf); 18 | } 19 | 20 | public static void combination_ManyCoins(int[] arr, int idx, int tar, int csum, String asf){ 21 | if(csum>tar){ 22 | return; 23 | } 24 | if(idx == arr.length){ 25 | if(csum==tar){ 26 | System.out.println(asf); 27 | } 28 | return; 29 | } 30 | 31 | // include (I can include the same coin again, so next call is with the same idx) 32 | combination_ManyCoins(arr, idx, tar, csum+arr[idx], asf+arr[idx]+","); 33 | 34 | // not include 35 | combination_ManyCoins(arr, idx+1, tar, csum, asf); 36 | } 37 | 38 | public static void combination(int[] arr, int idx, int tar, int csum, String asf){ 39 | if(csum>tar){ 40 | return; 41 | } 42 | if(idx == arr.length){ 43 | if(csum==tar){ 44 | System.out.println(asf); 45 | } 46 | return; 47 | } 48 | 49 | for(int j=idx; j you can use many coins in one go 52 | } 53 | } 54 | 55 | // https://course.acciojob.com/idle?question=00ef1a30-24e1-403f-a0b0-57d7b7d41cd9 56 | public static void getPermutations(int[] coins, int tar, int csum,boolean[] vis, String asf){ 57 | if(csum > tar){ 58 | return; 59 | } 60 | if(tar == csum){ 61 | System.out.println(asf); 62 | return; 63 | } 64 | 65 | for(int j=0; j curr, ArrayList> ans){ 7 | if(csum>tar) return; 8 | if(idx == arr.length){ 9 | if(tar==csum){ 10 | ans.add(new ArrayList<>(curr)); 11 | } 12 | return; 13 | } 14 | 15 | // include 16 | curr.add(arr[idx]); 17 | solve(arr,tar,idx+1,csum+arr[idx],curr,ans); 18 | curr.remove(curr.size()-1); 19 | 20 | // not include 21 | solve(arr,tar,idx+1,csum,curr,ans); 22 | } 23 | 24 | public static boolean canPlace(int row, int col, int num, char[][] board){ 25 | // check row 26 | for(int i=row,j=0; j<9; j++){ 27 | if(board[i][j]-'0'==num){ 28 | return false; 29 | } 30 | } 31 | 32 | // check col 33 | for(int i=0, j=col; i<9; i++){ 34 | if(board[i][j]-'0'==num){ 35 | return false; 36 | } 37 | } 38 | 39 | int sr = (row/3)*3; 40 | int sc = (col/3)*3; 41 | // check subGrid 42 | for(int i=sr; i points, int idx, char[][] board){ 54 | if(idx == points.size()){ 55 | return true; 56 | } 57 | 58 | int[] curr_points = points.get(idx); 59 | int row = curr_points[0]; 60 | int col = curr_points[1]; 61 | 62 | for(int num=1; num<=9; num++){ 63 | if(canPlace(row,col,num,board)==true){ 64 | board[row][col] = (char)(num+'0'); 65 | boolean ans = fillSudoku(points, idx+1, board); 66 | if(ans==true){ 67 | return true; 68 | } 69 | 70 | board[row][col]='.'; 71 | } 72 | } 73 | 74 | return false; 75 | } 76 | 77 | public static void solveSudoku(char[][] board) { 78 | ArrayList points = new ArrayList<>(); 79 | 80 | for(int i=0; i<9; i++){ 81 | for(int j=0; j<9; j++){ 82 | if(board[i][j]=='.'){ 83 | points.add(new int[]{i,j}); 84 | } 85 | } 86 | } 87 | 88 | fillSudoku(points,0,board); 89 | } 90 | public static void main(String[] args) { 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Module 5/Backtracking/Day 2/out.txt: -------------------------------------------------------------------------------- 1 | 2,3,7, 2 | 5,7, 3 | ============================================ 4 | 2,3,7, 5 | 5,7, 6 | -------------------------------------------------------------------------------- /Module 5/Backtracking/Day 3/PnC.java: -------------------------------------------------------------------------------- 1 | public class PnC { 2 | 3 | // https://course.acciojob.com/idle?question=47372dee-2349-43c2-ac5b-35dfd0c66583 4 | public static void permutations(int[] boxes, int ci, int ti){ 5 | if(ci > ti){ 6 | // print boxes and return 7 | for(int j=0; j tb){ 33 | if(itpsf == ts){ 34 | System.out.println(asf); 35 | } 36 | return; 37 | } 38 | 39 | // going to place item in this box 40 | combinations(cb+1,tb,itpsf+1,ts,asf+"i"); 41 | 42 | // wont place a item in this box 43 | combinations(cb+1,tb,itpsf,ts,asf+"-"); 44 | } 45 | 46 | // permutations using combination method =========================================================== 47 | public static void permutations(int cb, int tb, boolean[] items, int itpsf, int ts, String asf){ 48 | if(cb > tb){ 49 | if(itpsf == ts){ 50 | System.out.println(asf); 51 | } 52 | return; 53 | } 54 | 55 | // i can pick any of the remaining items 56 | for(int i=0; i ti){ 72 | for(int i=0; i=n || j>=m || i<0 || j<0){ 6 | return 0; 7 | } 8 | 9 | if(i==n-1 && j==m-1){ 10 | return matrix[i][j]; 11 | } 12 | 13 | // right direction 14 | int a = maxSum(i, j+1, matrix, n, m); 15 | 16 | // downwards direction 17 | int b = maxSum(i+1, j, matrix, n, m); 18 | 19 | int ans = Math.max(a,b) + matrix[i][j]; 20 | 21 | return ans; 22 | } 23 | 24 | public static void floodFill(int i, int j, int[][] mat, int n, int m, String psf,boolean[][] visited){ 25 | if(i<0 || j<0 || i>=n || j>=m || mat[i][j]==1 || visited[i][j] == true){ 26 | return; 27 | } 28 | 29 | if(i==n-1 && j==m-1){ 30 | System.out.println(psf); 31 | return; 32 | } 33 | 34 | visited[i][j] = true; 35 | floodFill(i-1, j, mat, n, m, psf+"t",visited); 36 | floodFill(i, j-1, mat, n, m, psf+"l",visited); 37 | floodFill(i+1, j, mat, n, m, psf+"d",visited); 38 | floodFill(i, j+1, mat, n, m, psf+"r",visited); 39 | visited[i][j] = false; 40 | } 41 | 42 | public static boolean isQueenSafe(int row, int col, boolean[][] board){ 43 | int n = board.length; 44 | 45 | int[][] dirs = {{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{-1,-1},{0,-1}}; 46 | 47 | for(int rad=1; rad=0 && j>=0 && i set1, ArrayList set2, int soset1,int soset2){ 24 | if(idx==arr.length){ 25 | int n = arr.length; 26 | if(n%2 ==0 && set1.size()==set2.size()){ 27 | return Math.abs(soset1 - soset2); 28 | } else if(n%2==1 && Math.abs(set1.size()-set2.size())==1){ 29 | return Math.abs(soset1 - soset2); 30 | } 31 | 32 | return Integer.MAX_VALUE; 33 | } 34 | 35 | set1.add(arr[idx]); 36 | int ans1 = minAbsoluteDiff(arr, idx + 1, set1, set2, soset1+arr[idx], soset2); 37 | set1.remove(set1.size()-1); 38 | 39 | set2.add(arr[idx]); 40 | int ans2 = minAbsoluteDiff(arr, idx + 1, set1, set2, soset1, soset2+arr[idx]); 41 | set2.remove(set2.size()-1); 42 | 43 | return Math.min(ans1,ans2); 44 | } 45 | } 46 | 47 | // https://course.acciojob.com/idle?question=caa4e30e-feae-4685-ba03-aeeb5faf8721 48 | public static int floodfill(int[][] arr, int n,boolean[][] visited, int i, int j){ 49 | if(i<0 || j<0 || i>=n || j>=n || arr[i][j]==0 || visited[i][j]==true){ 50 | return 0; 51 | } 52 | 53 | if(i==n-1 && j==n-1){ 54 | return 1; 55 | } 56 | 57 | int ans =0; 58 | 59 | visited[i][j]=true; 60 | ans+=floodfill(arr, n, visited, i + 1, j); 61 | ans+=floodfill(arr, n, visited, i - 1, j); 62 | ans+=floodfill(arr, n, visited, i, j + 1); 63 | ans+=floodfill(arr, n, visited, i, j - 1); 64 | visited[i][j]=false; 65 | 66 | return ans; 67 | } 68 | 69 | public static int totalPossibleWays(int[][] arr, int n) { 70 | boolean[][] visited = new boolean[n][n]; 71 | 72 | return floodfill(arr,n,visited,0,0); 73 | } 74 | public static void main(String[] args) { 75 | 76 | } 77 | } -------------------------------------------------------------------------------- /Module 5/DP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/DP.pdf -------------------------------------------------------------------------------- /Module 5/Dynamic Programming module 5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Dynamic Programming module 5.pdf -------------------------------------------------------------------------------- /Module 5/Dynamic Programming/Cut Type DP/Catalan.java: -------------------------------------------------------------------------------- 1 | public class Catalan { 2 | public static int uniqueBST_rec(int n){ 3 | if(n<=1){ 4 | return 1; 5 | } 6 | 7 | int ans=0; 8 | for(int i=1; i<=n; i++){ 9 | int left = uniqueBST_rec(i-1); 10 | int right = uniqueBST_rec(n-i); 11 | // int curr_ans = uniqueBST_rec(i-1) * uniqueBST_rec(n-i); 12 | 13 | ans+=(left*right); 14 | } 15 | 16 | return ans; 17 | } 18 | 19 | public static int uniqueBST_memo(int n, int[] dp){ 20 | if(n<=1){ 21 | return 1; 22 | } 23 | 24 | if(dp[n]!=0) return dp[n]; 25 | 26 | int ans=0; 27 | for(int i=1; i<=n; i++){ 28 | int left = uniqueBST_memo(i-1,dp); 29 | int right = uniqueBST_memo(n-i,dp); 30 | // int curr_ans = uniqueBST_rec(i-1) * uniqueBST_rec(n-i); 31 | 32 | ans+=(left*right); 33 | } 34 | 35 | return dp[n] = ans; 36 | } 37 | public static int uniqueBST(int n) { 38 | int[] memo = new int[n+1]; 39 | return uniqueBST_memo(n, memo); 40 | // return uniqueBST_rec(n); 41 | } 42 | 43 | // homework 44 | // https://practice.geeksforgeeks.org/problems/nth-catalan-number0817/1 45 | public static void main(String[] args) { 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Module 5/Dynamic Programming/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Dynamic Programming/Introduction/Main.class -------------------------------------------------------------------------------- /Module 5/Dynamic Programming/Introduction/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static int fib_rec(int n){ 3 | if(n==0 || n==1){ 4 | return n; 5 | } 6 | 7 | int ans = fib_rec(n-1) + fib_rec(n-2); 8 | 9 | return ans; 10 | } 11 | 12 | public static int fib_memo(int n, int[] memo){ 13 | if(n==0 || n==1){ 14 | return memo[n]=n; 15 | } 16 | 17 | if(memo[n]!=0) return memo[n]; 18 | 19 | int ans = fib_memo(n-1,memo) + fib_memo(n-2,memo); 20 | 21 | return memo[n]=ans; 22 | } 23 | 24 | public static int tabulation(int N, int[] memo){ 25 | for(int n=0; n<=N; n++){ 26 | if(n==0 || n==1){ 27 | memo[n]=n; 28 | continue; 29 | } 30 | 31 | // if(memo[n]!=0) return memo[n]; 32 | 33 | int ans = memo[n-1] + memo[n-2]; //fib_memo(n-1,memo) + fib_memo(n-2,memo); 34 | 35 | memo[n]=ans; 36 | } 37 | 38 | return memo[N]; 39 | } 40 | public static int tabulation(int N){ 41 | int[] dp = new int[N+1]; 42 | 43 | dp[0] = 0; 44 | dp[1] = 1; 45 | 46 | for(int n=2; n<=N; n++){ 47 | int ans = dp[n-1] + dp[n-2]; //fib_dp(n-1,dp) + fib_dp(n-2,dp); 48 | 49 | dp[n]=ans; 50 | } 51 | 52 | return dp[N]; 53 | } 54 | 55 | public static int fib_most_optimized(int n){ 56 | int f=0; 57 | int s=1; 58 | int t = f + s; 59 | 60 | for(int i=2; i<=n; i++){ 61 | t = f + s; 62 | f = s; 63 | s = t; 64 | } 65 | 66 | return t; 67 | } 68 | public static void main(String[] args) { 69 | int n = 7; 70 | 71 | int[] memo = new int[n+1]; 72 | int ans = fib_memo(n,memo); 73 | System.out.println(ans); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Module 5/Dynamic Programming/LIS set/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Dynamic Programming/LIS set/Main.class -------------------------------------------------------------------------------- /Module 5/Dynamic Programming/Misc/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | // leetcode 1277 ================================================================================ 3 | public int countSquares(int[][] matrix) { 4 | int n = matrix.length; 5 | int m = matrix[0].length; 6 | for(int i=1; i[] graph = new ArrayList[N]; 24 | 25 | public static void constructGraph(){ 26 | for(int i=0; i(); 28 | } 29 | 30 | addEdge(0,1,10); 31 | addEdge(0, 3, 40); 32 | addEdge(1, 2, 10); 33 | addEdge(2, 4, 10); 34 | addEdge(5, 4, 2); 35 | addEdge(4, 6, 5); 36 | addEdge(6, 7, 3); 37 | addEdge(6, 8, 3); 38 | // cycle 39 | addEdge(2, 3, 3); 40 | addEdge(1, 4, 3); 41 | } 42 | 43 | public static void addEdge(int u, int v, int w){ 44 | graph[u].add(new Edge(u, v, w)); 45 | graph[v].add(new Edge(v, u, w)); 46 | } 47 | 48 | // BFS ============================================================ 49 | public static void BFS(int src){ 50 | boolean[] vis = new boolean[N]; 51 | 52 | LinkedList que = new LinkedList<>(); 53 | 54 | que.add(src); 55 | int level = 0; 56 | 57 | while(que.size()>0){ 58 | int s = que.size(); 59 | System.out.print("This is level " + level+ " -> "); 60 | while(s-->0){ 61 | int vtx = que.removeFirst(); 62 | 63 | if(vis[vtx]==true){ 64 | System.out.println("There is a cycle" + vtx); 65 | continue; 66 | } 67 | 68 | vis[vtx] = true; 69 | System.out.print(vtx+" "); 70 | for(Edge e:graph[vtx]){ 71 | int nbr = e.v; 72 | if(!vis[nbr]){ 73 | que.addLast(nbr); 74 | } 75 | } 76 | } 77 | level++; 78 | System.out.println(); 79 | } 80 | } 81 | public static void main(String[] args) { 82 | constructGraph(); 83 | BFS(0); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Module 5/Graph/BFS/out.txt: -------------------------------------------------------------------------------- 1 | This is level 0 -> 0 2 | This is level 1 -> 1 3 3 | This is level 2 -> 2 4 There is a cycle2 4 | 5 | This is level 3 -> There is a cycle4 6 | 5 6 7 | This is level 4 -> 7 8 8 | -------------------------------------------------------------------------------- /Module 5/Graph/DFS Questions/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | // leetcode 200 (Number of islands) ================================================================= 3 | public void dfs(int i, int j, char[][] grid){ 4 | grid[i][j] = '0'; // changing land to water 5 | 6 | int[][] dirs = {{0,1},{1,0},{0,-1},{-1,0}}; 7 | 8 | for(int[] dir:dirs){ 9 | int x = i+dir[0]; 10 | int y =j + dir[1]; 11 | 12 | if(x>=0 && y>=0 && x=0 && y>=0 && x { 18 | int wsf; 19 | String psf; 20 | 21 | Pair(int wsf, String psf){ 22 | this.wsf = wsf; 23 | this.psf = psf; 24 | } 25 | 26 | public int compareTo(Pair o){ 27 | return this.wsf - o.wsf; 28 | } 29 | } 30 | 31 | static String lpath; // longest path 32 | static Integer lpathwt = Integer.MIN_VALUE; 33 | static String fpath; // path just smaller than criteria 34 | static Integer fpathwt = Integer.MIN_VALUE; 35 | static PriorityQueue pq = new PriorityQueue<>(); // pq 36 | public static void multisolver(ArrayList[] graph, int src, int dest, boolean[] visited, int criteria, int k, String psf, int wsf) { 37 | if(src==dest){ 38 | pq.add(new Pair(wsf,psf)); 39 | if(pq.size()>k){ 40 | pq.remove(); 41 | } 42 | 43 | if(wsf > lpathwt){ 44 | lpath = psf; 45 | lpathwt = wsf; 46 | } 47 | 48 | if(wsf < criteria && wsf > fpathwt){ 49 | fpathwt = wsf; 50 | fpath = psf ; 51 | } 52 | return; 53 | } 54 | 55 | visited[src] = true; 56 | 57 | for(Edge e: graph[src]){ 58 | int nbr = e.nbr; 59 | if(!visited[nbr]){ 60 | multisolver(graph, nbr, dest, visited, criteria, k, psf+nbr, wsf+e.wt); 61 | } 62 | } 63 | 64 | visited[src] = false; 65 | } 66 | 67 | // homework =========================== 68 | // https://course.acciojob.com/idle?question=ad1abf35-aa2c-4f0f-8fa3-46b85e164e4c 69 | boolean hasPath(int src, int des, ArrayList[] graph, boolean[] vis){ 70 | if(src == des){ 71 | return true; 72 | } 73 | 74 | boolean ans = false; 75 | vis[src]= true; 76 | for(int nbr: graph[src]){ 77 | if(!vis[nbr]){ 78 | ans = ans || hasPath(nbr, des, graph, vis); 79 | } 80 | } 81 | 82 | vis[src] = false; 83 | return ans; 84 | } 85 | 86 | boolean check(int N, int M, ArrayList> Edges,int U,int V) { 87 | // N vertices, M edges 88 | ArrayList[] graph = new ArrayList[N]; 89 | for(int i=0; i(); 91 | } 92 | 93 | for(ArrayList edge:Edges){ 94 | int u = edge.get(0); 95 | int v = edge.get(1); 96 | 97 | graph[u-1].add(v-1); 98 | } 99 | 100 | return hasPath(U-1, V-1, graph, new boolean[N]) || hasPath(V-1, U-1, graph,new boolean[N]); 101 | } 102 | 103 | public static int getSize(int src, boolean[] vis, ArrayList[] graph){ 104 | vis[src]= true; 105 | 106 | int ans = 0; 107 | for(Edge e: graph[src]){ 108 | int nbr = e.nbr; 109 | if(vis[nbr]==false){ 110 | int nbrSize = getSize(nbr, vis, graph); 111 | ans += nbrSize; 112 | } 113 | } 114 | 115 | return ans + 1; 116 | } 117 | public static int perfectStudents(int vtces, ArrayList[] graph){ 118 | ArrayList components = new ArrayList<>(); 119 | 120 | boolean[] visited = new boolean[vtces]; 121 | for(int i=0; i pq = new PriorityQueue<>((int[] t, int[] o) ->{ 9 | // return t[0] - o[0]; // min pq 10 | return o[1] - t[1]; 11 | }); 12 | 13 | for(int i=0; i data; 7 | 8 | public Heap(){ 9 | data = new ArrayList<>(); 10 | } 11 | 12 | private void swap(int i, int j){ 13 | int valAtI = data.get(i); 14 | int valAtJ = data.get(j); 15 | 16 | data.set(i,valAtJ); 17 | data.set(j,valAtI); 18 | } 19 | 20 | private void upHeapify(int ci){ 21 | int pi = (ci-1)/2; 22 | 23 | if(pi>=0 && data.get(pi) > data.get(ci)){ 24 | swap(ci,pi); 25 | upHeapify(pi); 26 | } 27 | } 28 | // add 29 | public void add(int val){ 30 | data.add(val); 31 | 32 | upHeapify(data.size()-1); 33 | } 34 | 35 | private void downHeapify(int pi){ 36 | int lci = 2*pi + 1; 37 | int rci = 2*pi + 2; 38 | 39 | int mini = pi; 40 | 41 | if(lci < data.size() && data.get(lci) < data.get(mini)){ 42 | mini = lci; 43 | } 44 | 45 | if(rci < data.size() && data.get(rci) < data.get(mini)){ 46 | mini = rci; 47 | } 48 | 49 | if(mini != pi){ 50 | swap(pi,mini); 51 | downHeapify(mini); 52 | } 53 | } 54 | // remove 55 | public int remove(){ 56 | if(data.size()==0){ 57 | System.out.println("There is no element in heap"); 58 | return -1; 59 | } 60 | 61 | swap(0,data.size()-1); 62 | int rv = data.remove(data.size()-1); 63 | 64 | downHeapify(0); 65 | 66 | return rv; 67 | } 68 | 69 | // peek 70 | public int peek(){ 71 | if(data.size()==0){ 72 | System.out.println("There is no element in heap"); 73 | return -1; 74 | } 75 | 76 | return data.get(0); 77 | } 78 | 79 | // size 80 | public int size(){ 81 | return data.size(); 82 | } 83 | } 84 | 85 | public static void main(String[] args) { 86 | Heap minPq = new Heap(); 87 | minPq.add(23); 88 | minPq.add(19); 89 | minPq.add(24); 90 | minPq.add(43); 91 | minPq.add(13); 92 | minPq.add(3); 93 | 94 | while(minPq.size()>0){ 95 | int ele = minPq.remove(); 96 | System.out.println(ele); 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /Module 5/Heap/ImplementationMax$MaxHeap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Heap/ImplementationMax$MaxHeap.class -------------------------------------------------------------------------------- /Module 5/Heap/ImplementationMax.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Heap/ImplementationMax.class -------------------------------------------------------------------------------- /Module 5/Heap/ImplementationMax.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class ImplementationMax { 4 | static class MaxHeap{ 5 | private ArrayList data; 6 | 7 | public MaxHeap(){ 8 | data = new ArrayList<>(); 9 | } 10 | 11 | private void swap(int i, int j){ 12 | int valAtI = data.get(i); 13 | int valAtJ = data.get(j); 14 | 15 | data.set(i,valAtJ); 16 | data.set(j,valAtI); 17 | } 18 | 19 | private void upHeapify(int ci){ 20 | int pi = (ci-1)/2; 21 | 22 | if(pi>=0 && data.get(pi) < data.get(ci)){ 23 | swap(ci,pi); 24 | upHeapify(pi); 25 | } 26 | } 27 | // add 28 | public void add(int val){ 29 | data.add(val); 30 | 31 | upHeapify(data.size()-1); 32 | } 33 | 34 | private void downHeapify(int pi){ 35 | int lci = 2*pi + 1; 36 | int rci = 2*pi + 2; 37 | 38 | int maxi = pi; 39 | 40 | if(lci < data.size() && data.get(lci) > data.get(maxi)){ 41 | maxi = lci; 42 | } 43 | 44 | if(rci < data.size() && data.get(rci) > data.get(maxi)){ 45 | maxi = rci; 46 | } 47 | 48 | if(maxi != pi){ 49 | swap(pi,maxi); 50 | downHeapify(maxi); 51 | } 52 | } 53 | // remove 54 | public int remove(){ 55 | if(data.size()==0){ 56 | System.out.println("There is no element in heap"); 57 | return -1; 58 | } 59 | 60 | swap(0,data.size()-1); 61 | int rv = data.remove(data.size()-1); 62 | 63 | downHeapify(0); 64 | 65 | return rv; 66 | } 67 | 68 | // peek 69 | public int peek(){ 70 | if(data.size()==0){ 71 | System.out.println("There is no element in heap"); 72 | return -1; 73 | } 74 | 75 | return data.get(0); 76 | } 77 | 78 | // size 79 | public int size(){ 80 | return data.size(); 81 | } 82 | } 83 | 84 | public static void main(String[] args) { 85 | MaxHeap pq = new MaxHeap(); 86 | pq.add(23); 87 | pq.add(19); 88 | pq.add(24); 89 | pq.add(43); 90 | pq.add(13); 91 | pq.add(3); 92 | 93 | while(pq.size()>0){ 94 | int ele = pq.remove(); 95 | System.out.println(ele); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Module 5/Heap/PQIntroduction.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Heap/PQIntroduction.class -------------------------------------------------------------------------------- /Module 5/Heap/PQIntroduction.java: -------------------------------------------------------------------------------- 1 | import java.util.Collections; 2 | import java.util.PriorityQueue; 3 | 4 | class Student implements Comparable { 5 | int roll_no; 6 | String name; 7 | int class_no; 8 | 9 | public Student(int roll_no, String name, int class_no){ 10 | this.roll_no = roll_no; 11 | this.name = name; 12 | this.class_no = class_no; 13 | } 14 | 15 | public int compareTo(Student other){ 16 | // return this.roll_no - other.roll_no; // min pq 17 | // return other.roll_no - this.roll_no //=> max pq 18 | 19 | // return this.class_no - other.class_no; // smaller class number on the top of pq 20 | return other.class_no - this.class_no; // larger class number on the top 21 | } 22 | 23 | public String toString(){ 24 | return "Name = " + this.name + " , Roll number = " + this.roll_no; 25 | } 26 | } 27 | 28 | public class PQIntroduction { 29 | public static void main(String[] args) { 30 | 31 | // PriorityQueue maxPq = new PriorityQueue<>(Collections.reverseOrder()); // max Pq 32 | // PriorityQueue minPq = new PriorityQueue<>(); /// min pq 33 | PriorityQueue pq = new PriorityQueue<>(); 34 | 35 | Student s1 = new Student(1, "Accio",2); 36 | Student s2 = new Student(2, "Job",5); 37 | Student s3 = new Student(-10, "Ram",10); 38 | 39 | pq.add(s1); 40 | pq.add(s2); 41 | pq.add(s3); 42 | System.out.println(pq.peek()); 43 | // System.out.println(s1); 44 | // System.out.println(s2); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Module 5/Heap/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/Heap/Student.class -------------------------------------------------------------------------------- /Module 5/String DP.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Module 5/String DP.pdf -------------------------------------------------------------------------------- /Offline/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/.DS_Store -------------------------------------------------------------------------------- /Offline/2D Arrays/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/2D Arrays/Introduction/Main.class -------------------------------------------------------------------------------- /Offline/2D Arrays/Introduction/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void main(String[] args){ 3 | int[][] arr = new int[5][3]; 4 | 5 | int count = 1; 6 | 7 | for(int i=0; i al= new ArrayList<>(); 8 | 9 | for(int i=0; i<5; i++){ 10 | int val = scn.nextInt(); 11 | al.add(val); 12 | } 13 | 14 | int sum = 0; 15 | int product = 1; 16 | 17 | for(int i=0; i=0 && arr[i-1] == arr[i]){ 12 | continue; 13 | } 14 | int first_ele = arr[i]; 15 | int target_left = target - arr[i]; 16 | 17 | int twoSumPairs = twoSumBetweenIndices(arr, target_left, i+1, n-1); 18 | ans += twoSumPairs; 19 | } 20 | return ans; 21 | } 22 | 23 | public static int twoSumBetweenIndices(int[] arr, int target, int left, int right){ 24 | int number_of_pairs = 0; 25 | 26 | while(left < right){ 27 | int csum = arr[left] + arr[right]; 28 | 29 | if(csum < target){ 30 | left++; 31 | } else if(csum > target){ 32 | right--; 33 | } else { 34 | number_of_pairs++; 35 | int curr_ele = arr[right]; 36 | 37 | while(left target){ 60 | right--; 61 | } else { 62 | number_of_pairs++; 63 | right--; 64 | } 65 | } 66 | 67 | return number_of_pairs; 68 | } 69 | 70 | 71 | // pascal triangle =================================== 72 | public static ArrayList> pascalTriangle(int numRows) { 73 | ArrayList> ans = new ArrayList<>(); 74 | 75 | ArrayList past = new ArrayList<>(); 76 | past.add(1); 77 | ans.add(past); 78 | 79 | int total_number_of_line = numRows - 1; 80 | 81 | while(total_number_of_line > 0){ 82 | ArrayList curr = new ArrayList<>(); 83 | 84 | for(int i=1; i pascalTriangleRow(int numRows) { 101 | ArrayList past = new ArrayList<>(); 102 | past.add(1); 103 | 104 | int total_number_of_line = numRows - 1; 105 | 106 | while(total_number_of_line > 0){ 107 | ArrayList curr = new ArrayList<>(); 108 | 109 | for(int i=1; i> ans = pascalTriangle(5); 128 | System.out.println(ans); 129 | } 130 | } -------------------------------------------------------------------------------- /Offline/Arrays/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Arrays/Introduction/Main.class -------------------------------------------------------------------------------- /Offline/Arrays/Introduction/Main.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | 4 | int[] arr = new int[5]; 5 | int[] arr2 = {1,2,3,4,5,5}; 6 | 7 | arr[0] = 10; 8 | arr[1] = 20; 9 | arr[2] = 30; 10 | arr[3] = 40; 11 | arr[4] = 50; 12 | 13 | for(int ele: arr){ 14 | System.out.println(ele); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Offline/Arrays/Introduction/Swap.java: -------------------------------------------------------------------------------- 1 | public class Swap { 2 | public static void swapValues(int[] arr){ 3 | int temp = arr[0]; 4 | arr[0] = arr[1]; 5 | arr[1] = temp; 6 | } 7 | public static void main(String[] args) { 8 | int[] arr = new int[2]; 9 | arr[0] = 4; 10 | arr[1] = 10; 11 | 12 | System.out.println(arr[0]); 13 | System.out.println(arr[1]); 14 | 15 | swapValues(arr); 16 | 17 | System.out.println(arr[0]); 18 | System.out.println(arr[1]); 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Offline/Class 2/Conditionals/Calculator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Class 2/Conditionals/Calculator.class -------------------------------------------------------------------------------- /Offline/Class 2/Conditionals/Calculator.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Calculator { 4 | public static void main(String[] args) { 5 | int a = 10; 6 | 7 | if(a++ == 11){ // first comparison, then increment (post increment) 8 | System.out.println("value of a is 11"); 9 | } 10 | if(--a == 10){ 11 | System.out.println("Value of a is 95"); 12 | } 13 | a--; 14 | 15 | System.out.println(a); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Offline/Class 2/Conditionals/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Class 2/Conditionals/Main.class -------------------------------------------------------------------------------- /Offline/Class 2/Conditionals/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner scn = new Scanner(System.in); 6 | int num = scn.nextInt(); 7 | 8 | int remainder = num%2; 9 | if(remainder == 0){ 10 | System.out.println("Number is even"); 11 | } else { 12 | System.out.println("Number is odd"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Offline/Class 2/Conditionals/ReportCard.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Class 2/Conditionals/ReportCard.class -------------------------------------------------------------------------------- /Offline/Class 2/Conditionals/ReportCard.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ReportCard { 4 | public static void main(String[] args) { 5 | Scanner scn = new Scanner(System.in); 6 | 7 | int marks = scn.nextInt(); // 85 8 | 9 | if(marks>90){ 10 | System.out.println("Excellent"); 11 | } else if(marks>80){ // marks<=90 12 | System.out.println("Very good"); 13 | } else if(marks>60){ 14 | System.out.println("Good"); 15 | } else { 16 | System.out.println("Bye"); 17 | } 18 | } 19 | } 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | // if(marks>90){ 32 | // System.out.println("Excellent"); 33 | // } 34 | // if(marks>80 && marks<=90){ 35 | // System.out.println("Very Good"); 36 | // } 37 | // if(marks>60 && marks<=80){ 38 | // System.out.println("Good"); 39 | // } 40 | // if(marks<60){ 41 | // System.out.println("Bye"); 42 | // } 43 | -------------------------------------------------------------------------------- /Offline/Class 2/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner scn = new Scanner(System.in); 6 | 7 | int num = scn.nextInt(); // 12345 8 | 9 | int fifth_digit = num % 10; // 12345 % 10 = 5 10 | 11 | // removing fifth_digit 12 | num = num/10; // num = 1234 13 | 14 | int fourth_digit = num % 10; 15 | 16 | // removing fourth_digit 17 | num = num/10; 18 | 19 | int third_digit = num%10; 20 | 21 | // removing third_digit 22 | num = num/10; 23 | 24 | int second_digit = num%10; 25 | // removing second_digit 26 | num = num/10; 27 | 28 | int first_digit = num%10; 29 | // removing first_digit 30 | num = num/10; 31 | 32 | int ans = first_digit + fourth_digit; 33 | System.out.println(ans); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Offline/Class 2/Questions.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Class 2/Questions.class -------------------------------------------------------------------------------- /Offline/Class 2/Questions.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Questions { 4 | public static void main(String[] args) { 5 | Scanner scn = new Scanner(System.in); 6 | 7 | int num = scn.nextInt(); // 12345 8 | 9 | int first_digit = num/10000; 10 | 11 | // removing last (fifth) digit 12 | num = num/10; // 1234 13 | 14 | int fourth_digit = num%10; 15 | 16 | int ans = first_digit + fourth_digit; 17 | 18 | System.out.println(ans); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Offline/Functions/Questions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Functions/Questions/Main.class -------------------------------------------------------------------------------- /Offline/Functions/Questions/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | // bonary to decimal 5 | public static int binaryToDecimal(int binaryNumber) { 6 | int res = 0; 7 | int curr_pow_of_two = 1; 8 | 9 | while(binaryNumber > 0){ 10 | int ld = binaryNumber % 10; 11 | 12 | res = res + ld * curr_pow_of_two; 13 | 14 | binaryNumber=binaryNumber / 10; 15 | curr_pow_of_two=curr_pow_of_two * 2; 16 | } 17 | 18 | return res; 19 | } 20 | 21 | // calculate nCr 22 | public static int fact(int x){ 23 | int ans = 1; 24 | for(int i=1; i<=x; i++){ 25 | ans = ans * i; 26 | } 27 | 28 | return ans; 29 | } 30 | 31 | public static int calculate_nCr(int n, int r) { 32 | int fact_of_n = fact(n); 33 | int fact_of_r = fact(r); 34 | int fact_of_n_minus_r = fact(n-r); 35 | 36 | int result = fact_of_n / (fact_of_r * fact_of_n_minus_r); 37 | 38 | return result; 39 | } 40 | public static void main(String[] args) { 41 | Scanner scanner = new Scanner(System.in); 42 | int n = scanner.nextInt(); 43 | int r = scanner.nextInt(); 44 | int ans = calculate_nCr(n,r); 45 | System.out.print(ans); 46 | System.out.print(global_Var); 47 | } 48 | } -------------------------------------------------------------------------------- /Offline/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Introduction/Main.class -------------------------------------------------------------------------------- /Offline/Introduction/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args) { 5 | Scanner scn = new Scanner(System.in); 6 | 7 | int num = scn.nextInt(); 8 | 9 | int fd = 0; 10 | int sd = 0; 11 | int td = 0; 12 | 13 | td = num % 10; // retrieve my last digit 14 | 15 | // i dont need my third digit 16 | num = num/10; // deleting my last digit 17 | 18 | sd = num%10; 19 | num = num/10; 20 | 21 | fd = num%10; 22 | num = num/10; 23 | 24 | int reversedNumber = td*100 + sd*10 + fd*1; 25 | System.out.println(reversedNumber); 26 | } 27 | } -------------------------------------------------------------------------------- /Offline/Introduction/Questions.java: -------------------------------------------------------------------------------- 1 | public class Questions { 2 | public static void main(String[] args) { 3 | System.out.println("*****"); 4 | System.out.println(" * "); 5 | System.out.println(" * "); 6 | System.out.println(" * "); 7 | System.out.println("*****"); 8 | 9 | 10 | // Fahrenheit to celcius 11 | 12 | // Scanner scn = new Scanner(System.in); 13 | 14 | // int fahr = scn.nextInt(); 15 | 16 | // int celcius = ((fahr-32)*5)/9; 17 | 18 | // System.out.println(celcius); 19 | } 20 | 21 | // Homework 22 | 23 | // Write a program to calculate the sum of the first and the second last digit of a 5 digit. 24 | // E.g.- NUMBER : 12345 OUTPUT : 1+4=5 25 | } 26 | -------------------------------------------------------------------------------- /Offline/LinkedList/Design Browser History/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) throws Throwable { 5 | Scanner sc = new Scanner(System.in); 6 | String homepage = sc.nextLine(); 7 | int n = sc.nextInt(); 8 | sc.nextLine(); 9 | BrowserHistory browserHistory = new BrowserHistory(homepage); 10 | for(int i = 0; i < n; i++) { 11 | String q = sc.nextLine(); 12 | String[] query = q.split("\\s+"); 13 | if(query[0].equals("visit")){ 14 | browserHistory.visit(query[1]); 15 | } else if(query[0].equals("back")){ 16 | browserHistory.back(Integer.parseInt(query[1])); 17 | } else if(query[0].equals("forward")){ 18 | browserHistory.forward(Integer.parseInt(query[1])); 19 | } 20 | } 21 | } 22 | } 23 | class Node { 24 | String data; 25 | Node next; 26 | Node prev; 27 | 28 | public Node(String data){ 29 | this.data = data; 30 | } 31 | } 32 | 33 | class BrowserHistory { 34 | Node curr; 35 | // Node head; 36 | public BrowserHistory(String homepage) { 37 | // your code here 38 | Node nn = new Node(homepage); 39 | // head = nn; 40 | curr = nn; 41 | } 42 | 43 | public void visit(String url) { 44 | Node nn = new Node(url); 45 | 46 | curr.next = nn; 47 | nn.prev = curr; 48 | 49 | curr = nn; 50 | } 51 | 52 | public void back(int steps) { 53 | while(steps > 0 && curr.prev != null){ // while(steps > 0 && curr != head){ 54 | curr = curr.prev; 55 | steps--; 56 | } 57 | System.out.println(curr.data); 58 | } 59 | 60 | public void forward(int steps) { 61 | while(steps > 0 && curr.next != null){ 62 | curr = curr.next; 63 | steps--; 64 | } 65 | 66 | System.out.println(curr.data); 67 | } 68 | } -------------------------------------------------------------------------------- /Offline/LinkedList/Introduction/LinkedList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/LinkedList/Introduction/LinkedList$Node.class -------------------------------------------------------------------------------- /Offline/LinkedList/Introduction/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/LinkedList/Introduction/LinkedList.class -------------------------------------------------------------------------------- /Offline/LinkedList/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/LinkedList/Introduction/Main.class -------------------------------------------------------------------------------- /Offline/LinkedList/Introduction/Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/LinkedList/Introduction/Node.class -------------------------------------------------------------------------------- /Offline/Loops/Example.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Loops/Example.class -------------------------------------------------------------------------------- /Offline/Loops/Example.java: -------------------------------------------------------------------------------- 1 | public class Example { 2 | public static int addNumbers(int x, int y){ 3 | System.out.println("Starting of function"); 4 | 5 | int sum = x + y; 6 | System.out.println(sum); 7 | 8 | return sum; 9 | } 10 | public static void main(String[] args) { 11 | System.out.println("This is line 1"); 12 | 13 | int y = 44; 14 | int res = addNumbers(23, y); 15 | 16 | System.out.println(res); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Offline/Loops/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | public static void main(String[] args) { 4 | Scanner sc = new Scanner(System.in); 5 | 6 | // int i; 7 | // boolean isPrime = true; 8 | // for(i=2; i 0){ 26 | int ld = num%10; 27 | num = num/10; 28 | 29 | ans = ans*10 + ld; 30 | } 31 | 32 | System.out.println(ans); 33 | } 34 | } -------------------------------------------------------------------------------- /Offline/Loops/NumberPatterns/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Loops/NumberPatterns/Main.class -------------------------------------------------------------------------------- /Offline/Loops/NumberPatterns/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void numberDiamond(int n){ 5 | int total_number_of_line = 2*n-1; 6 | int current_number_of_line = 1; 7 | 8 | int stars = 1; 9 | int spaces = n-1; 10 | 11 | while(current_number_of_line <= total_number_of_line){ 12 | // print spaces 13 | for(int i=1; i<=spaces; i++){ 14 | System.out.print(" "); 15 | } 16 | 17 | // print stars 18 | int number_to_print = 1; 19 | for(int i=1; i<=stars; i++){ 20 | System.out.print(number_to_print+" "); 21 | if(i <= stars/2){ 22 | number_to_print++; 23 | } else { 24 | number_to_print--; 25 | } 26 | } 27 | 28 | 29 | // prepare for next line 30 | if(current_number_of_line < n){ 31 | stars = stars + 2; 32 | spaces--; 33 | } else { 34 | stars = stars - 2; 35 | spaces++; 36 | } 37 | System.out.println(); 38 | current_number_of_line++; 39 | } 40 | } 41 | public static void main(String[] args) { 42 | Scanner scn = new Scanner(System.in); 43 | int n = scn.nextInt(); 44 | 45 | // int total_number_of_line = n; 46 | // int current_number_of_line = 1; 47 | // int stars = 1; 48 | // int spaces= n-1; 49 | 50 | // while(current_number_of_line <= total_number_of_line){ 51 | // // print stars 52 | // for(int i=1; i<=stars; i++){ 53 | // System.out.print(i+" "); 54 | // } 55 | 56 | // // print spaces 57 | // for(int i=1; i<=spaces; i++){ 58 | // System.out.print(" "); 59 | // } 60 | 61 | // // prepare for next line 62 | // System.out.println(); 63 | // stars++; 64 | // spaces--; 65 | // current_number_of_line++; 66 | // } 67 | 68 | // int total_number_of_line = n; 69 | // int current_number_of_line = 1; 70 | // int number_to_print = 1; 71 | // int stars = n; 72 | // int spaces= 0; 73 | 74 | // while(current_number_of_line <= total_number_of_line){ 75 | // // print spaces 76 | // for(int i=1; i<=spaces; i++){ 77 | // System.out.print(" "); 78 | // } 79 | 80 | // // print stars 81 | // for(int i=1; i<=stars; i++){ 82 | // System.out.print(number_to_print+" "); 83 | // number_to_print++; 84 | // } 85 | 86 | // // prepare for next line 87 | // System.out.println(); 88 | // spaces++; 89 | // stars--; 90 | // current_number_of_line++; 91 | // } 92 | 93 | numberDiamond(n); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Offline/Loops/Patterns/DiamondPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Main{ 3 | public static void main(String[] args){ 4 | //Write your code here 5 | //Take required input and print the output 6 | Scanner scn = new Scanner(System.in); 7 | int t = scn.nextInt(); 8 | while(t > 0){ 9 | int n = scn.nextInt(); 10 | int current_number_of_line = 1; 11 | int total_number_of_line = n; 12 | int stars = 1; 13 | int spaces = n/2; 14 | 15 | while(current_number_of_line <= total_number_of_line){ 16 | // print spaces 17 | for(int i=1; i<=spaces; i++){ 18 | System.out.print(" "); 19 | } 20 | 21 | // print stars 22 | for(int i=1; i<=stars; i++){ 23 | System.out.print("* "); 24 | } 25 | 26 | // prepare for next line 27 | System.out.println(); 28 | if(current_number_of_line <= n/2){ 29 | spaces--; 30 | stars = stars+2; 31 | } else { 32 | spaces++; 33 | stars = stars-2; 34 | } 35 | current_number_of_line++; 36 | } 37 | 38 | t--; 39 | } 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /Offline/Loops/Patterns/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Loops/Patterns/Main.class -------------------------------------------------------------------------------- /Offline/Loops/Patterns/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner scn = new Scanner(System.in); 6 | int n = scn.nextInt(); 7 | 8 | // int current_number_of_line = 1; 9 | // int total_number_of_line = n; 10 | // int stars = 1; 11 | // int spaces = n-1; 12 | 13 | // while(current_number_of_line <= total_number_of_line){ 14 | // // print spaces 15 | // for(int i=0; i 300){ 16 | this.salary = 0; 17 | } else { 18 | this.salary = newSalary; 19 | } 20 | } 21 | 22 | public int getSalary(String password){ // getters 23 | if(password == "ABCD"){ 24 | return this.salary; 25 | } else { 26 | System.out.println("Thieffffff"); 27 | return -1; 28 | } 29 | } 30 | } 31 | 32 | 33 | class Main { 34 | public static void main(String[] args){ 35 | Employee e = new Employee(); 36 | 37 | e.setSalary(1000000); 38 | System.out.println(e.getSalary("1234")); 39 | } 40 | } -------------------------------------------------------------------------------- /Offline/OOPS/encapsulation/Main2.java: -------------------------------------------------------------------------------- 1 | package encapsulation; 2 | class Main2 { 3 | public static void main(String[] args){ 4 | Vechile v = new Vechile(); 5 | 6 | v.color = "Red"; 7 | 8 | System.out.println(v.color); 9 | } 10 | } -------------------------------------------------------------------------------- /Offline/OOPS/encapsulation/Question.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/OOPS/encapsulation/Question.class -------------------------------------------------------------------------------- /Offline/OOPS/encapsulation/Question.java: -------------------------------------------------------------------------------- 1 | class Student { 2 | String name; 3 | int roll_no; 4 | private int marks; 5 | 6 | public char getGrade(){ 7 | if(this.marks >= 85){ 8 | return 'A'; 9 | } else if(this.marks >= 60){ 10 | return 'B'; 11 | } else if(this.marks >= 45){ 12 | return 'C'; 13 | } else if(this.marks >= 33){ 14 | return 'D'; 15 | } else { 16 | return 'F'; 17 | } 18 | } 19 | 20 | public void setMarks(int marks){ 21 | if(marks > 100 || marks < 0){ 22 | System.out.println("NOT POSSIBLE!!"); 23 | } else { 24 | this.marks = marks; 25 | } 26 | } 27 | 28 | public int getMarks(){ 29 | return this.marks; 30 | } 31 | } 32 | 33 | class Question { 34 | public static void main(String[] args){ 35 | Student s = new Student(); 36 | 37 | s.setMarks(85); 38 | System.out.println(s.getGrade()); 39 | 40 | s.setMarks(-5); 41 | System.out.println(s.getGrade()); 42 | } 43 | } -------------------------------------------------------------------------------- /Offline/OOPS/encapsulation/Student.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/OOPS/encapsulation/Student.class -------------------------------------------------------------------------------- /Offline/OOPS/encapsulation/Vechile.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/OOPS/encapsulation/Vechile.class -------------------------------------------------------------------------------- /Offline/OOPS/encapsulation/Vechile.java: -------------------------------------------------------------------------------- 1 | public class Vechile { 2 | String color; 3 | } -------------------------------------------------------------------------------- /Offline/Recursion/Backtracking/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static int countAllPaths(int i, int j, int n, int m, int[][] matrix, boolean[][] visited){ 3 | if(i<0 || j<0 || i>=n || j>=m || visited[i][j] == true || matrix[i][j] == 1){ 4 | return 0; 5 | } 6 | 7 | if(i==n-1 && j==m-1){ 8 | System.out.println("Found one path!!"); 9 | return 1; 10 | } 11 | 12 | visited[i][j] = true; // stops you from going to a cell of current_path 13 | 14 | int totalWays = 0; 15 | totalWays += countAllPaths(i-1, j, n, m, matrix, visited); // top 16 | totalWays += countAllPaths(i, j-1, n, m, matrix, visited); // left 17 | totalWays += countAllPaths(i+1, j, n, m, matrix, visited); // down 18 | totalWays += countAllPaths(i, j+1, n, m, matrix, visited); // right 19 | 20 | visited[i][j] = false; // why? backtracking 21 | return totalWays; 22 | } 23 | 24 | public static void printAllPaths(int i, int j, int n, int m, int[][] matrix, boolean[][] visited, String psf){ 25 | if(i<0 || j<0 || i>=n || j>=m || visited[i][j] == true || matrix[i][j] == 1){ 26 | return; 27 | } 28 | 29 | if(i==n-1 && j==m-1){ 30 | System.out.println(psf); 31 | return; 32 | } 33 | 34 | visited[i][j] = true; // stops you from going to a cell of current_path 35 | 36 | printAllPaths(i-1, j, n, m, matrix, visited, psf + "t"); // top 37 | printAllPaths(i, j-1, n, m, matrix, visited, psf + "l"); // left 38 | printAllPaths(i+1, j, n, m, matrix, visited, psf + "d"); // down 39 | printAllPaths(i, j+1, n, m, matrix, visited, psf + "r"); // right 40 | 41 | visited[i][j] = false; // why? backtracking 42 | } 43 | 44 | public void printPermutations(String str, String asf) { 45 | if(str.equals("")){ 46 | System.out.println(asf); 47 | return; 48 | } 49 | 50 | for(int i=0; i0 && str.charAt(i-1) == str.charAt(i)){ // distinct 52 | continue; 53 | } 54 | String beforeString = str.substring(0,i); 55 | String afterString = str.substring(i+1); 56 | 57 | String smallerString = beforeString + afterString; 58 | printPermutations(smallerString, asf + str.charAt(i)); 59 | } 60 | } 61 | 62 | public static void main(String[] args){ 63 | int[][] matrix = {{0,1,0,0,0,0},{0,1,0,1,1,0},{0,0,0,0,0,0},{0,1,0,1,1,0},{0,1,0,1,1,0},{0,0,0,1,1,0}}; 64 | 65 | int n = matrix.length; 66 | int m = matrix[0].length; 67 | printAllPaths(0,0,n,m,matrix,new boolean[n][m],""); 68 | } 69 | } -------------------------------------------------------------------------------- /Offline/Recursion/Get Questions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/Get Questions/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/IQuestions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/IQuestions/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/IQuestions/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static long ways(int n, int start_coin){ 3 | if(n==0){ 4 | return 1; 5 | } 6 | 7 | if(start_coin > n){ 8 | return 0; 9 | } 10 | 11 | long waysAfterIncludingCurrentCoin = ways(n - start_coin, start_coin + 1); 12 | long waysAfterNotIncludingCurrentCoin = ways(n, start_coin + 1); 13 | 14 | long totalWays = waysAfterIncludingCurrentCoin + waysAfterNotIncludingCurrentCoin; 15 | 16 | return totalWays; 17 | } 18 | 19 | 20 | public static long ways2(int n, int start_coin){ // combinations 21 | if(n==0){ 22 | return 1; 23 | } 24 | 25 | if(start_coin > n){ 26 | return 0; 27 | } 28 | long totalWays = 0; 29 | 30 | for(int coin = start_coin; coin <=n; coin++){ 31 | long rec_ways = ways2(n-coin, coin+1); 32 | totalWays += rec_ways; 33 | } 34 | return totalWays; 35 | } 36 | 37 | public static void main(String[] args){ 38 | int[][] dirs = {{-1,0},{0,1},{1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}}; 39 | 40 | for(int[] dir: dirs){ // {-1,0} 41 | int newRow = row + dir[0]; 42 | int newCol = col + dir[1]; 43 | 44 | rec(newRow,newCol); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Offline/Recursion/Introduction/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/Introduction/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/Introduction/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static long product(int n){ 3 | if(n == 1){ 4 | return 1; 5 | } 6 | 7 | long smallAns = product(n-1); 8 | long ans = n * smallAns; 9 | 10 | return ans; 11 | } 12 | 13 | public static void printDecreasingIncreasing(int n){ 14 | if(n == 1){ 15 | System.out.println(1); 16 | return; 17 | } 18 | 19 | System.out.println(n); 20 | printDecreasingIncreasing(n-1); 21 | System.out.println(n); 22 | } 23 | 24 | public static void printIncreasing(int n){ 25 | if(n == 0){ 26 | return; 27 | } 28 | 29 | printIncreasing(n-1); 30 | System.out.println(n); 31 | } 32 | 33 | 34 | public static void printNumbers(int n){ 35 | if(n == 0){ 36 | return; 37 | } 38 | 39 | System.out.println(n); 40 | printNumbers(n-1); 41 | } 42 | 43 | public static void swap2(int a, int b){ 44 | int temp = a; 45 | a = b; 46 | b = temp; 47 | } 48 | 49 | public static void swap(int a, int b){ 50 | swap2(b,a); 51 | 52 | } 53 | 54 | public static int sum(int a, int b){ 55 | int ans = a + b; 56 | return ans; 57 | } 58 | 59 | public static void printZigZag(int n){ 60 | if(n == 0){ 61 | return; 62 | } 63 | 64 | System.out.println(n + "Pre"); 65 | 66 | printZigZag(n-1); 67 | 68 | System.out.println(n + "In"); 69 | 70 | printZigZag(n-1); 71 | 72 | System.out.println(n + "Post"); 73 | } 74 | public static void main(String[] args){ 75 | // int x = 5; 76 | // int y = 45; 77 | 78 | // int ans = sum(x,y); 79 | // System.out.println(ans); 80 | printZigZag(2); 81 | } 82 | } -------------------------------------------------------------------------------- /Offline/Recursion/Print Questions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/Print Questions/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/Print Questions/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static void printSubsequences(String str, String asf){ 3 | if(str.equals("")){ 4 | System.out.println(asf); 5 | return; 6 | } 7 | 8 | char currChar = str.charAt(0); 9 | String smallerString = str.substring(1); 10 | 11 | printSubsequences(smallerString, asf); // currChar said no 12 | printSubsequences(smallerString, asf + currChar); // currChar said yes 13 | } 14 | 15 | static String[] sarr = {"*#,","abc","def","ghi","jkl","mno","pqrs","tu","vwx","yz"}; 16 | public static void printKPC(String str, String asf){ 17 | if(str.equals("")){ 18 | System.out.print(asf+" "); 19 | return; 20 | } 21 | 22 | char firstChar = str.charAt(0); // "789" -> '7' 23 | String smallerString = str.substring(1); 24 | 25 | int idx = firstChar - '0'; // 7 26 | String key = sarr[idx]; 27 | 28 | for(int i=0; i=n || j>=m){ 56 | return; 57 | } 58 | 59 | printMazePaths(i,j+1,n,m, asf +"h"); 60 | printMazePaths(i+1,j,n,m, asf +"v"); 61 | } 62 | 63 | // "303", "1234" 64 | public static void printEncodings(String str, String asf){ 65 | if(str.equals("")){ 66 | System.out.println(asf); 67 | return; 68 | } 69 | if(str.charAt(0) == '0'){ 70 | return; 71 | } 72 | 73 | String smallerString = str.substring(1); // "234" 74 | int firstNum = str.charAt(0) - '0'; // 1 75 | char toAdd = (char)(firstNum - 1 + 'a'); // 'a' 76 | 77 | printEncodings(smallerString, asf + toAdd); // {"234", "a"} 78 | 79 | 80 | if(str.length() >= 2){ 81 | String first2NumberString = str.substring(0,2); // "12","3" 82 | int first2Nums = Integer.parseInt(first2NumberString); // 12 83 | 84 | if(first2Nums <= 26){ 85 | toAdd = (char)(first2Nums - 1 + 'a'); // l 86 | String anotherSmallerString = str.substring(2); //"34" 87 | 88 | printEncodings(anotherSmallerString, asf + toAdd); 89 | } 90 | } 91 | } 92 | 93 | 94 | public static void main(String[] args){ 95 | // printSubsequences("abc",""); 96 | // printKPC("789",""); 97 | // printStairPaths(3,""); 98 | printMazePaths(0,0,3,3,""); 99 | } 100 | } -------------------------------------------------------------------------------- /Offline/Recursion/Questions/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/Questions/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/Questions/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static int power(int x, int y){ 3 | if(y == 0){ 4 | return 1; 5 | } 6 | 7 | int smallerAns = power(x, y-1); 8 | int ans = smallerAns * x; 9 | 10 | return ans; 11 | } 12 | 13 | public static int power_better(int x, int y){ 14 | if(y==0){ 15 | return 1; 16 | } 17 | int smallerAns = power_better(x, y/2); 18 | 19 | int ans = smallAns * smallAns; // O(logY) 20 | // int ans = power_better(x, y/2) * power_better(x, y/2); O(Y) 21 | 22 | if(y % 2 != 0){ 23 | ans = x*ans; 24 | } 25 | 26 | return ans; 27 | } 28 | 29 | // Tower of HANOI ============================================ 30 | public static void toh(int n, int A, int C, int B){ 31 | if(n==0){ 32 | return; 33 | } 34 | 35 | toh(n-1, A, B, C); 36 | // move nth ring from A to C 37 | System.out.println("Moving " + n + " ring from " + A + " -> " + C); 38 | 39 | toh(n-1, B, C, A); 40 | } 41 | 42 | // fibonacci series ========================= 43 | public static int fib(int n){ 44 | if(n == 0){ 45 | return 0; 46 | } 47 | if(n == 1){ 48 | return 1; 49 | } 50 | 51 | int lastTerm = fib(n-1); 52 | int secondLastTerm = fib(n-2); 53 | 54 | int nthTerm = lastTerm + secondLastTerm; 55 | return nthTerm; 56 | } 57 | 58 | // product of first n natural numbers ======================= 59 | public static long product(int n){ 60 | if(n == 1){ 61 | return 1; 62 | } 63 | 64 | long smallAns = 0; 65 | smallAns = product(n-1); 66 | long ans = n * smallAns; 67 | 68 | return ans; 69 | } 70 | 71 | public static void main(String[] args){ 72 | // printDecreasingIncreasing(5); 73 | // int a = 5, b=7; 74 | // int n = 4; 75 | // fib(n); 76 | 77 | // int sum = a + b; 78 | toh(4,10,30,20); 79 | } 80 | } -------------------------------------------------------------------------------- /Offline/Recursion/Recursion in Arrays/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/Recursion in Arrays/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/Recursion in Arrays/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static int[] allOccurrences(int[] arr, int idx, int tar, int count){ 3 | if(idx == arr.length){ 4 | int[] ba = new int[count]; 5 | return ba; 6 | } 7 | 8 | int[] ans; 9 | if(arr[idx] == tar){ 10 | ans = allOccurrences(arr, idx + 1, tar, count + 1); 11 | } else { 12 | ans = allOccurrences(arr, idx + 1, tar, count); 13 | } 14 | 15 | if(arr[idx] == tar){ 16 | ans[count] = idx; 17 | } 18 | 19 | return ans; 20 | } 21 | public static int LastOccurrence(int[] arr, int idx, int tar){ 22 | if(idx == arr.length){ 23 | return -1; 24 | } 25 | 26 | int lastOccurrenceValue = LastOccurrence(arr, idx+1, tar); 27 | 28 | if(lastOccurrenceValue == -1){ 29 | if(arr[idx] == tar){ 30 | return idx; 31 | } 32 | } 33 | 34 | return lastOccurrenceValue; 35 | } 36 | 37 | public static int firstOccurrence(int[] arr, int idx, int tar){ 38 | if(idx == arr.length){ 39 | return -1; 40 | } 41 | 42 | int furtherFirstOccurrence = firstOccurrence(arr, idx+1, tar); 43 | 44 | if(arr[idx] == tar){ 45 | return idx; 46 | } 47 | 48 | return furtherFirstOccurrence; 49 | } 50 | 51 | public static void printArrayReverse(int[] arr, int idx){ 52 | if(idx == arr.length){ 53 | return; 54 | } 55 | 56 | printArrayReverse(arr, idx + 1); 57 | System.out.println(arr[idx]); 58 | } 59 | 60 | public static void printArray(int[] arr, int idx){ 61 | if(idx == arr.length){ 62 | return; 63 | } 64 | 65 | System.out.println(arr[idx]); 66 | printArray(arr, idx + 1); 67 | } 68 | 69 | public static void main(String[] args){ 70 | int[] arr = {5, 9, 10, 11, 8, 11, 11, 4, 5}; 71 | System.out.println(LastOccurrence(arr,0,11)); 72 | } 73 | } -------------------------------------------------------------------------------- /Offline/Recursion/Sorting/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Samrat-Bhardwaj/Accio/ea98d4bade6acb03b0462d8d7c8492b821745da1/Offline/Recursion/Sorting/Main.class -------------------------------------------------------------------------------- /Offline/Recursion/Sorting/Main.java: -------------------------------------------------------------------------------- 1 | class Main { 2 | public static int[] merge2sortedArray(int[] nums1, int n, int[] nums2, int m){ 3 | int[] ans = new int[n+m]; 4 | 5 | int i = 0; 6 | int j = 0; 7 | int k = 0; 8 | 9 | while(i < n && j < m){ 10 | if(nums1[i] < nums2[j]){ 11 | ans[k] = nums1[i]; 12 | i++; 13 | } else { 14 | ans[k] = nums2[j]; 15 | j++; 16 | } 17 | 18 | k++; 19 | } 20 | 21 | while(i < n){ 22 | ans[k] = nums1[i]; 23 | i++; 24 | k++; 25 | } 26 | 27 | while(j < m){ 28 | ans[k] = nums2[j]; 29 | j++; 30 | k++; 31 | } 32 | 33 | return ans; 34 | } 35 | 36 | // MERGE SORT ================================================================= 37 | public static void mergeSortedArrays(int[] arr, int left, int mid, int right){ 38 | int n = mid - left + 1; 39 | int m = right - mid; 40 | 41 | int[] nums1 = new int[n]; 42 | int[] nums2 = new int[m]; 43 | 44 | int curr_idx = left; 45 | for(int i=0; i= right){ 86 | return; 87 | } 88 | 89 | int mid = (left + right)/2; 90 | 91 | mergeSort(arr,left,mid); 92 | mergeSort(arr,mid+1,right); 93 | 94 | // {left,mid} {mid+1, right} -> merge 95 | mergeSortedArrays(arr,left,mid,right); 96 | } 97 | 98 | public static void swap(int[] nums, int i, int j){ 99 | int temp = nums[i]; 100 | nums[i] = nums[j]; 101 | nums[j] = temp; 102 | } 103 | 104 | // {0,i} -> smaller than pivot 105 | // {i+1,j-1} -> greater than pivot 106 | // {j,end} -> unknown area 107 | public int[] pivotArray(int[] nums, int pivot) { 108 | int i = -1; 109 | int j = 0; 110 | 111 | while(j < nums.length){ 112 | if(nums[j] <= pivot){ 113 | i++; 114 | swap(nums,i,j); 115 | j++; 116 | } else { 117 | j++; 118 | } 119 | } 120 | 121 | return nums; 122 | } 123 | 124 | public static int partition(int[] arr, int left, int right){ 125 | int pivot = arr[right]; 126 | 127 | int i = left - 1; 128 | int j = left; 129 | 130 | while(j < right){ 131 | if(arr[j] <= pivot){ 132 | i++; 133 | swap(arr,i,j); 134 | j++; 135 | } else { 136 | j++; 137 | } 138 | } 139 | 140 | swap(arr, i+1, right); 141 | 142 | return (i+1); 143 | } 144 | 145 | public static void quickSort(int[] arr, int left, int right){ 146 | if(left >= right){ 147 | return; 148 | } 149 | 150 | int partitionIdx = partition(arr,left,right); 151 | 152 | quickSort(arr,left,partitionIdx - 1); 153 | quickSort(arr,partitionIdx+1,right); 154 | } 155 | 156 | public static void main(String[] args){ 157 | int[] arr = {10,1,4,9,7,11,2}; 158 | 159 | quickSort(arr,0,6); 160 | 161 | for(int i=0; i