├── DSA Sheet ├── 01. Array │ ├── 001. Search an Element in an Array │ │ ├── Iterative Approach.cpp │ │ └── Recursive Approach.cpp │ ├── 003. Missing Element of AP │ │ ├── Brute Force Approach.cpp │ │ ├── Iterative Binary Search Approach.cpp │ │ └── Recursive Binary Search Approach.cpp │ ├── 006. Binary Array Sorting │ │ ├── Count Sort.cpp │ │ ├── Two Pointer Approach.cpp │ │ └── Zeros First.cpp │ ├── 007. Move all Negative Elements to End │ │ ├── Iterative Approach.cpp │ │ └── Recursive Approach.cpp │ ├── 009. Search a 2D Matrix │ │ └── Binary Search Approach.cpp │ ├── 015. Equilibrium Point │ │ ├── ArraySum Approach.cpp │ │ └── Two Pointer Approach.cpp │ ├── 017. Find Transition Point │ │ ├── Binary Search Approach.cpp │ │ └── Brute Force Approach.cpp │ ├── 018. Alternate Positive and Negative Numbers │ │ └── Iterative Approach.cpp │ ├── 019. Union of Two Sorted Arrays │ │ └── Two Pointer Approach.cpp │ ├── 020. Three Way Partitioning │ │ ├── InBuilt Function Approach.cpp │ │ └── One Pointer Approach.cpp │ ├── 022. Min Subsets with Consecutive Numbers │ │ └── Sort and Count Approach.cpp │ ├── 024. Rearrange Array Alternately │ │ └── Solution.cpp │ ├── 026. Rearrange an Array with O(1) Extra Space │ │ └── Solution.cpp │ ├── 027. Count Triplets with Sum smaller than X │ │ └── Solution.cpp │ ├── 029. Row with Max 1s │ │ ├── Binary Search Approach.cpp │ │ └── Linear Approach.cpp │ └── 036. Watering Plants │ │ └── Solution.cpp └── Coder Army Sheet.xlsx └── Data Structures and Algorithms ├── #180DaysOfCode └── Tracker.md ├── Class Illustrations ├── 022. Binary Search with Theory and Code │ └── Binary Search.cpp ├── 038. Longest Palindrome || Sorting the Sentence │ ├── 1. Longest Palindrome.cpp │ └── 2. Sorting the Sentence.cpp ├── 041. Sliding Window Protocol on Strings │ ├── 1. Longest Substring Without Repeating Characters.cpp │ └── 2. Smallest Distinct Window.cpp ├── 044. Strings HARD Problems For Coding Round │ ├── 1. Minimum Characters to be added at front to make String Palindrome.cpp │ └── 2. Repeated String Match.cpp ├── 059. Merge Sort Algorithm │ └── Sort an Array.cpp ├── 060. Quick Sort Algorithm │ └── Quick Sort.cpp ├── 067. Josephus Problem || Predict the Winner │ └── Optimized Approach.cpp ├── 068. Recursion Rat in a Maze Problem │ └── Rat in a Maze.cpp ├── 081. Linked List LeetCode Problem: Remove Every Kth Node | Rotate List | Palindrome List │ ├── 1. Remove Nth Node From End of List.cpp │ └── 2. Remove every kth node.cpp ├── 087. Hard Problem on Linked List: Flattening a Linked List | Merge K Sorted Linked List │ ├── 1. Flattening a Linked List.cpp │ └── 2. Merge K sorted linked lists.cpp ├── 090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop │ ├── 2. Insert an Element at the Bottom of a Stack.cpp │ ├── 3. Make the array beautiful.cpp │ ├── 4. String Manipulation.cpp │ ├── 9. Print Bracket Number.cpp │ └── 98-88. Get min at pop.cpp ├── 092. Stack Problem: Largest Rectangle in Histogram | Maximal Rectangle │ └── 1. Largest Rectangle in Histogram.cpp ├── 094. Stack Hard: Maximum of minimum for every window Size | Get Minimum Element from Stack │ └── 1. Get minimum element from stack.cpp ├── 097. Print all Elements in Queue | Implement Queue using Stack | Implement Stack using Queue │ ├── 2. Queue Reversal.cpp │ ├── 3. Reverse First K elements of Queue.cpp │ ├── 4.1 Time Needed to Buy Tickets.cpp │ ├── 4.2 Time Needed to Buy Tickets.cpp │ └── 5. Implement Queue using Stacks.cpp ├── 098. Queues with Sliding Window Problems │ └── 2. First negative integer in every window of size k.cpp └── 101. Introduction To Trees | Binary Tree in Data Structure │ └── Build the Binary Tree.cpp └── HomeWork Sheets ├── 001. Introduction To Programming for Beginners ├── Day 1_180 Introduction To Programming (Home work).pdf ├── HomeWork Sheet Answers └── HomeWork Sheet Link ├── 002. Introduction to FlowCharts and PseudoCode in Programming ├── Day 2_180 Flowchart and PseudoCode.pdf └── HomeWork Sheet Link ├── 003. Start C++ from Zero and Write Your First Program ├── Day 3_180 Introduction to C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ └── 1. Product.cpp ├── 004. If Else Statement in C++ || Loop in C++ ├── Day 4_180 If-Else and For Loop.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── For Loop │ ├── 1. World Cup 2023.cpp │ ├── 2. Odd Numbers till N.cpp │ └── 3. Divisible by 4 till N.cpp │ └── If-Else │ ├── 1. Bigger Number.cpp │ ├── 2. Adult or Teenager.cpp │ ├── 3. Month Number.cpp │ └── 4. Ticket Price Calculator.cpp ├── 005. For Loop in C++ Advance || Prime Number || Factorial || Fibonacci || Sum of n number ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. 280 to 250.cpp │ ├── 2. A to Z.cpp │ ├── 3. Z to A.cpp │ ├── 4. Arithmetic Progression.cpp │ ├── 5. Sum of Squares.cpp │ └── 6. Sum of Cubes.cpp ├── 006. Solve Any Pattern Problem With Simple Trick Part-1 ├── Day 8_180_ Pattern Printing.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1st Pattern.cpp │ ├── 2nd Pattern.cpp │ ├── 3rd Pattern.cpp │ └── 4th Pattern.cpp ├── 007. Solve Any Pattern Problem with Simple Trick Part-2 ├── Day 9_180_ Pattern Printing-2.pdf └── HomeWork Sheet Link ├── 008. Solve HARD Pattern Print Problem with Simple Trick ├── Day 10_180_ Pattern Printing-2.pdf └── HomeWork Sheet Link ├── 009. Top 5 Advance Pattern Print Problems ├── Day 11_180_ Pattern Printing- Super Hard.pdf └── HomeWork Sheet Link ├── 010. Operators in C++ with Implementation ├── Day 12_180 Operator in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Temperature Range.cpp │ ├── 2. Even and Positive.cpp │ ├── 3. Age Check.cpp │ └── 4. Either Greater.cpp ├── 011. While and Do While Loop || Switch || Break || Continue in C++ ├── Day 15_180 While, do While , Switch c++.pdf └── HomeWork Sheet Link ├── 012. Binary To Decimal || Decimal To Binary || Decimal To Octal || Binary To Octal Conversion ├── Day 16_180 Binary to Decimal Conversion.pdf └── HomeWork Sheet Link ├── 013. Write Your First Program On LeetCode ├── Day 17_180 - Sheet1.pdf └── HomeWork Sheet Link ├── 014. Functions in C++ || Pass by Value || Pass by Reference ├── Day 18_180 Function in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Cube.cpp │ ├── 2. Reverse.cpp │ ├── 3. Swap of 3.cpp │ └── 4. Swap.cpp ├── 015. C++ Series End here ├── Day 19_180 C++ Series end here.pdf └── HomeWork Sheet Link ├── 016. Introduction To Arrays in C++ ├── Day 22_180 Introduction to Arrays in c++.pdf └── HomeWork Sheet Link ├── 017. Master Arrays By Solving Problems ├── Day 23_180 Master arrays by solving Problem.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 2. Move all Negative Elements to End.cpp │ ├── 3. Number of Occurrence.cpp │ ├── 4. Count Number of Elements between Two given Elements in Array.cpp │ └── 6. Sum of Unique Elements.cpp ├── 018. Time and Space Complexity From Zero To Advance ├── Day 24_180 Time and Space Complexity.pdf └── HomeWork Sheet Link ├── 019. SELECTION SORT Algorithm with Theory and Code ├── Day 25_180 Selection Sort in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Decreasing Order.cpp │ ├── 2. Highest to Last.cpp │ ├── 3. Sort the Char Array.cpp │ └── Solution_of_Day_25_180_Selection_Sort_in_C.pdf ├── 020. Bubble Sort with Theory and Code ├── Day 26_180 Bubble Sort in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ └── 1. Decreasing Order.cpp ├── 021. Insertion Sort with Theory and Code ├── Day 29_180 Insertion Sort in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Decreasing Order.cpp │ └── 2. Sort from Last.cpp ├── 022. Binary Search with Theory and Code ├── Day 30_180 Binary Search in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Search in Decreasing Order.cpp │ └── 2. Search Insert Position.cpp ├── 023. Binary Search Different Problem ├── Day 31_180 Binary Search Problem Solving.pdf └── HomeWork Sheet Link ├── 024. Binary Search Problem Solving-2 ├── Day 32_180 Binary Search Problem Part 2.pdf └── HomeWork Sheet Link ├── 025. Binary Search Top Interview Problem || Book Allocation || Painter Partition || Ship Package ├── Day 33_180 Binary Search Interview Problem.pdf └── HomeWork Sheet Link ├── 026. Binary Search Hard Interview Problem || Aggressive Cow || KOKO Eating Banana ├── Day 36_180 Binary Search Hard Interview Problem.pdf └── HomeWork Sheet Link ├── 027. What is STL || Vector in C++ ├── Day 37_180 Vector in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Proof of Average Time Complexity of push_back() Operation.pdf │ ├── 2. Number of Occurrences.cpp │ ├── 3. Maximum and Minimum.cpp │ ├── 4. Lower and Upper Bound.cpp │ ├── 5. Pass By Reference.cpp │ └── 5. Pass By Value.cpp ├── 028. Two Pointer in C++ | TWO SUM | Pair Sum | Pair Difference | Move 0 to end ├── Day 38_180 Two Pointer in C++.pdf └── HomeWork Sheet Link ├── 029. Kadane's Algorithm || Prefix and Suffix Sum || Array into 2 equal Sum Subarray ├── Day 39_180 Kadane’s Algorithm.pdf └── HomeWork Sheet Link ├── 030. Trapping Rain Water || 3 SUM || 4 SUM ├── Day 40_180 Trapping Rain water.pdf └── HomeWork Sheet Link ├── 031. 2D Arrays in C++ ├── Day 43_180 Introduction to 2D array in c++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Sum ColumnWise.cpp │ ├── 2. A-B.cpp │ ├── 3. Sum of Diagonals.cpp │ ├── 4. Column Major Order │ ├── 5. Largest Element.cpp │ └── 6. Smallest Element.cpp ├── 032. 2D Arrays Interview Problems || Wave Form || Spiral Form || Transpose Matrix || Column Major Order ├── Day 44_180 2D arrays Interview Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Transpose of Matrix.cpp │ ├── 2. Reverse Columns.cpp │ ├── 3. Spiral Matrix.cpp │ ├── 4. Spiral Matrix II.cpp │ ├── 5. Print Diagonally.cpp │ └── 7. Print Matrix in Snake Pattern.cpp ├── 033. Rotate Image | Rotate by 90 degree | Rotate Matrix Element Clockwise | Rotate Matrix by 180 Degree ├── Day 45_180 Rotate Matrix in C++.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Rotate Image.cpp │ ├── 2. Matrix Rotation by 180 Degree.cpp │ └── 3. Rotate by 90 degree AntiClockwise.cpp ├── 034. Binary Search in 2D Arrays || Search in a sorted row-col wise Matrix ├── Day 46_180 Binary Search in 2D Arrays.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Binary Search.cpp │ ├── 2. Search in a Row-Column Sorted Matrix.cpp │ └── 3. Count Zeros in a Sorted Matrix.cpp ├── 035. Solving Hard Problems On Arrays With Simple Logic || Majority Elements || Count Frequency of Element ├── Day 47_180 Solving Hard Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Finding Missing and Repeating Elements.cpp │ ├── 2. Count Frequency of Elements.cpp │ ├── 3.1 Majority Element.cpp │ ├── 3.2 Majority Element.cpp │ └── 4. Smallest Missing Positive Integer.cpp ├── 037. String Interviews Problem Solving || Sort a String └── HomeWork Sheet Solutions │ ├── 1. Defanging an IP Address.cpp │ ├── 2. Check if String is Rotated by Two Places.cpp │ └── 3. Check if the Sentence Is Pangram.cpp ├── 038. Longest Palindrome || Sorting the Sentence └── HomeWork Sheet Solutions │ ├── 1. Longest Palindrome.cpp │ └── 2. Sorting the Sentence.cpp ├── 039. Strings Interview Problems on LeetCode || Add Strings || Sort Vowels in a String └── HomeWork Sheet Solutions │ ├── 1. Add Strings.cpp │ ├── 2. Sort Vowels in a String.cpp │ └── 3. Case-Specific Sorting of Strings.cpp ├── 040. Factorial of Large Number || Integer to Roman || Roman to Integer └── HomeWork Sheet Solutions │ ├── 2. Integer to Roman.cpp │ └── 3. Roman to Integer.cpp ├── 041. Sliding Window Protocol on Strings ├── Day 57_180 Solving Hard Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Longest Substring Without Repeating Characters.cpp │ ├── 2. Smallest Distinct Window.cpp │ ├── 3. Smallest window containing 0, 1 and 2.cpp │ ├── 4. Longest K unique characters substring.cpp │ └── Day_57_180_Sliding_window_problem_on_String.pdf ├── 042. KMP Algorithm || Longest Prefix Suffix ├── Day 58_180 KMP Algorithm.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Longest Prefix Suffix.cpp │ ├── 2. Find the Index of the First Occurrence in a String.cpp │ └── Day_58_180_KMP_Algorithm.pdf ├── 043. String Matching || KMP Algorithm ├── Day 59_180 String Matching KMP Algorithm.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Find the Index of the First Occurrence in a String.cpp │ └── 2. Search Pattern (KMP-Algorithm).cpp ├── 044. Strings HARD Problems For Coding Round ├── Day 60_180 Strings HARD Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Minimum Characters to be added at front to make String Palindrome.cpp │ ├── 2. Repeated String Match.cpp │ └── 4. Shortest Palindrome.cpp ├── 045. Pointers in C++ || Introduction to Pointers in C++ ├── Day 61_180 Pointers in C++.pdf └── HomeWork Sheet Link ├── 046. Pointers Relationship with array || Arithmetic Pointers ├── Day 64_180 Pointers Arithmetic.pdf └── HomeWork Sheet Link ├── 047. Pointers with Character Arrays and Functions ├── Day 65_180 Pointers with Character Arrays and Functions.pdf └── HomeWork Sheet Link ├── 048. Double Pointer and Multiple Pointers in C++ ├── Day 66_180 Double Pointer in c++.pdf └── HomeWork Sheet Link ├── 050. Dynamic Memory Allocation of 2D and 3D Arrays in C++ ├── Day 71_180 Dynamic Memory Allocation of 2D and 3D Arrays.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 2. Deallocate 3D Array.cpp │ └── 3. Dynamic 4D Arrays.cpp ├── 051. Introduction To Recursion From Basic To Advance ├── Day 72_180 Introduction to Recursion.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Coder Army.cpp │ ├── 2. Odd Numbers from n to 1.cpp │ ├── 3. Numbers from 1 to N.cpp │ └── Solution_of_Day_72_180_Introduction_to_Recursion.pdf ├── 052. How To Solve Recursion Problem from 4 Different Method ├── Day 73_180 Solving Recursion From 4 Method.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Odd Numbers from 1 to N.cpp │ ├── 2. Numbers from 10 to N.cpp │ ├── 3. Table of n.cpp │ └── Solution_of_Day_73_180_Solving_Recursion_From_4_Method.pdf ├── 053. Recursion: Factorial of a Number | Sum of N numbers | Power of number | Sum of Square of N Numbers ├── Day 74_180 4 problems in One shot.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Sum of Cubes.cpp │ ├── 2. Power of Four.cpp │ ├── 3. Prime or Not.cpp │ └── Solution_of_Day_74_180_4_problems_in_One_shot.pdf ├── 054. Recursion Problems on Leetcode ├── Day 75_180 Recursion Problem on Leetcode.pdf └── HomeWork Sheet Link ├── 055. Recursion in Arrays ├── Day 78_180 Recursion in Arrays.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solution │ ├── 1. Maximum Element.cpp │ ├── 2. Product of All Elements.cpp │ ├── 3. Number Of Evens.cpp │ └── Solution_of_Day_78_180_Recursion_in_Arrays.pdf ├── 056. Recursion in Strings ├── Day 79_180 Recursion in Strings.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Check Palindrome.cpp │ ├── 2. Lower Case to Upper Case.cpp │ ├── 3. Convert String to LowerCase.cpp │ ├── 4. Reverse a String.cpp │ ├── 5. Number of Consonants.cpp │ └── Solution_of_Day_79_180_Recursion_in_Strings.pdf ├── 057. Recursion in Binary Search ├── Day 80_180 Recursion in Binary Search.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Binary Search for Non-Increasing Order.cpp │ ├── 2. Reverse Array Recursively.cpp │ ├── 3. Rotate Right Once.cpp │ └── Solution_of_Day_80_180_Recursion_in_Binary_Search.pdf ├── 058. Time Complexity and Space Complexity in Recursion ├── Day 81_180 Time and Space Complexity in Recursion.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── Answers │ └── Solution_of_Day_81_180_Time_and_Space_Complexity_in_Recursion.pdf ├── 059. Merge Sort Algorithm ├── Day 82_180 Merge Sort.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Merge Sort for Non-Increasing Order.cpp │ ├── 2. Count Inversions.cpp │ └── Solution_of_Day_82_180_Merge_Sort.pdf ├── 060. Quick Sort Algorithm ├── Day 85_180 Quick Sort.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Quick Sort for Descending Order.cpp │ └── Day_85_180__Quick_Sort_.pdf ├── 061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses ├── Day 86_180 Recursion on Subsequence.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Subsets.cpp │ ├── 2. Generate Parentheses.cpp │ ├── 3. Sums Of Subsequences.cpp │ └── Day_86_180_Recursion_on_Subsequence_.pdf ├── 062. Recursion on Subset Sum || Target Sum ├── Day 87_180 Recursion on Subset.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Subset Sums.cpp │ └── 2. Subset Sums & Subsets.cpp ├── 063. Recursion Perfect Sum Problem || Target Sum with Repetition ├── Day 88_180 Recursion_ Perfect Sum Problem.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solution │ └── 1. Subset with sum divisible by m.cpp ├── 064. Permutation of Arrays and Strings ├── Day 89_180 Permutations of Arrays.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Permutations of Array.cpp │ ├── 2. Permutations of a given String.cpp │ ├── 3. Permutations II.cpp │ └── Day_89_180_Permutations_of_Arrays_.pdf ├── 065. Permutation with repetition || Ways to Sum N ├── Day 92_180 Recursion permutation 2.pdf └── HomeWork Sheet Link ├── 068. Recursion Rat in a Maze Problem └── Rat in a Maze.cpp ├── 069. Print N-bit binary numbers having more 1s than 0s └── Print N-bit binary numbers having more 1s than 0s.cpp ├── 070. Introduction To Object Oriented Programming ├── Day 99_180 Object Oriented Programming.pdf └── HomeWork Sheet Link ├── 071. Constructor and Destructor in C++ ├── Day 100_180 Constructor and Destructor.pdf └── HomeWork Sheet Link ├── 072. Object Oriented Programming: Static data Member and Function | Encapsulation | Abstraction in C++ ├── Day 101_180 Static data member.pdf └── HomeWork Sheet Link ├── 074. Type of Inheritance in C++ | Single Inheritance | Multiple | Hybrid | Multipath | Multilevel ├── Day 106_180 Type of Inheritance.pdf └── HomeWork Sheet Link ├── 075. Polymorphism and Virtual Function in C++ ├── Day 107_180 Polymorphism.pdf └── HomeWork Sheet Link ├── 080. Reverse a Linked List | Middle of Linked List | Rotate Linked List └── HomeWork Solution │ └── Rotate List.cpp ├── 082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List ├── Day 119_180 Doubly Linked List.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 2. Doubly linked list Insertion at given position.cpp │ ├── 3. Reverse a Doubly Linked List.cpp │ └── Day_119_180_Doubly_Linked_List.pdf ├── 083. LinkedList Problems: Remove Duplicates | Merge 2 Sorted LinkedList | Sort a LinkedList of 0 1 and 2 ├── Day 120_180 LinkedList Problems.pdf └── HomeWork Sheet Link ├── 084. Circular Linked List: Detect Loop in Linked List || Find Length of Loop ├── Day 121_180 Circular LinkedList Problems.pdf └── HomeWork Sheet Link ├── 086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size ├── Day 123_180 LinkedList Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Reverse a sublist of a linked list.cpp │ └── Day_123_180_LinkedList_Problems.pdf ├── 087. Hard Problem on Linked List: Flattening a Linked List | Merge K Sorted Linked List ├── Day 126_180 LinkedList Problems.pdf └── HomeWork Sheet Link ├── 088. LinkedList Series End Here: Clone a linked list with next and random pointer ├── Day 127_180 LinkedList Problems.pdf └── HomeWork Sheet Link ├── 089. Introduction To STACK || Implement Stack Using Arrays and LinkedList ├── Day 133_180 Introduction to Stack.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Implement stack using array.cpp │ ├── 2. Implement Stack using Linked List.cpp │ ├── 3. Stack Operations.cpp │ └── Soltuion_of_Day_133_180_Introduction_to_Stack.pdf ├── 090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop ├── Day 134_180 Stack Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions │ ├── 1. Backspace String Compare.cpp │ └── 4. Minimum Add to Make Parentheses Valid.cpp └── 091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem ├── Day 135_180 Stack More Problems.pdf ├── HomeWork Sheet Link └── HomeWork Sheet Solutions ├── 2. Baseball Game.cpp ├── 4. Next Greater.cpp └── Solution_of_Day_135_180_Stack_More_Problems.pdf /DSA Sheet/01. Array/001. Search an Element in an Array/Iterative Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Check for each element in array if it equals to X. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | // Function to search x in arr 9 | // arr: input array 10 | // X: element to be searched for 11 | int search(int arr[], int N, int X) 12 | { 13 | for (int i = 0; i < N; i++){ 14 | if(arr[i] == X){ 15 | return i; 16 | } 17 | } 18 | return -1; 19 | } 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/001. Search an Element in an Array/Recursive Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Using Recursion, check at each recursive call if arr[index] equals to X till index becomes equal to N. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(N) 5 | */ 6 | class Solution{ 7 | public: 8 | // Function to search x in arr 9 | // arr: input array 10 | // X: element to be searched for 11 | int search(int arr[], int N, int X, int index = 0) 12 | { 13 | if(index == N) 14 | return -1; 15 | if(arr[index] == X) 16 | return index; 17 | return search(arr, N, X, index+1); 18 | } 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/003. Missing Element of AP/Brute Force Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> First, find the common difference of AP, then find the index where common difference of 2 terms don't match the common difference of AP. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | int findMissing(int arr[], int n) { 9 | int d = (arr[n-1] - arr[0]) / n; 10 | for (int i = 0; i < n-1; i++){ 11 | if(arr[i+1] - arr[i] != d) 12 | return arr[i] + d; 13 | } 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/003. Missing Element of AP/Iterative Binary Search Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> First, find the common difference of AP, then apply Binary Search to check if middle element is at its right position or not in the required AP. 3 | * Time Complexity -> O(log N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | int findMissing(int arr[], int n) { 9 | int d = (arr[n-1] - arr[0]) / n; 10 | int start = 0, end = n - 1, ans; 11 | while(start <= end){ 12 | int mid = start + (end - start)/2; 13 | if(arr[mid]==(arr[0]+mid*d)) 14 | start = mid + 1; 15 | else{ 16 | ans = arr[0] + mid*d; 17 | end = mid - 1; 18 | } 19 | } 20 | return ans; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/003. Missing Element of AP/Recursive Binary Search Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> First, find the common difference of AP. Then apply Binary Search recursively till the position of the missing element is obtained by checking the correctness of position of middle element, with respect to the required AP. 3 | * Time Complexity -> O(log N) 4 | * Space Complexity -> O(log N) 5 | */ 6 | class Solution{ 7 | public: 8 | int BinarySearch(int arr[], int start, int end, int d){ 9 | if(start > end){ 10 | return start; /* or return end+1; */ 11 | } 12 | int mid = start + (end - start) / 2; 13 | if(arr[mid] == arr[0] + mid*d) 14 | return BinarySearch(arr, start+1, end, d); 15 | else 16 | return BinarySearch(arr, start, end-1, d); 17 | } 18 | int findMissing(int arr[], int n) { 19 | int diff = (arr[n-1] - arr[0]) / n; 20 | return arr[0] + BinarySearch(arr,0,n-1,diff) * diff; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/006. Binary Array Sorting/Count Sort.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Count zeros or ones in the given array. Then assign values 0 and 1 to given array based on the found count of the zeros or ones. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | // A[]: input array 9 | // N: input array 10 | //Function to sort the binary array. 11 | void binSort(int A[], int N) 12 | { 13 | int zeros = 0; 14 | for (int i = 0; i < N; i++){ 15 | zeros += A[i]==0; 16 | } 17 | for (int i = 0; i < zeros; i++){ 18 | A[i] = 0; 19 | } 20 | for (int i = zeros; i < N; i++){ 21 | A[i] = 1; 22 | } 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/006. Binary Array Sorting/Two Pointer Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Take a pointer zeros pointing to 0th index, and another pointer ones which points to the last index. If zeros point to 1 and ones point to 0 swap values at both indexes and keep incrementing zeros or decrementing ones till zeros < ones. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | // A[]: input array 9 | // N: input array 10 | //Function to sort the binary array. 11 | void binSort(int A[], int N) 12 | { 13 | int zeros = 0, ones = N-1; 14 | while(zeros < ones){ 15 | if(A[zeros] == 0) 16 | zeros++; 17 | else if(A[ones] == 1) 18 | ones--; 19 | else 20 | swap(A[zeros++],A[ones--]); 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/006. Binary Array Sorting/Zeros First.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Take a pointer index which points to the index till which given array has continuous zeroes. Then iterate over the array, and whenever a zero is found, swap it with value at pointer index and then, pointer index is incremented. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | // A[]: input array // N: input array 9 | //Function to sort the binary array. 10 | void binSort(int A[], int N) 11 | { 12 | int index = 0; 13 | for (int i = 0; i < N; i++){ 14 | if(A[i] == 0) 15 | swap(A[i], A[index++]); 16 | } 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/007. Move all Negative Elements to End/Iterative Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Create two vectors, pushback positive elements to one, negative to other. Then copy values of these vectors to original array. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(N) 5 | */ 6 | class Solution{ 7 | public: 8 | void segregateElements(int arr[],int n) 9 | { 10 | int index = 0; 11 | vector positive, negative; 12 | for (int i = 0; i < n; i++){ 13 | if (arr[i] < 0) 14 | negative.push_back(arr[i]); 15 | else 16 | positive.push_back(arr[i]); 17 | } 18 | if (positive.size() == n || positive.size() == 0) return; 19 | for (int i = 0; i < positive.size(); i++){ 20 | arr[index++] = positive[i]; 21 | } 22 | for (int i = 0; i < negative.size(); i++){ 23 | arr[index++] = negative[i]; 24 | } 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/009. Search a 2D Matrix/Binary Search Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool searchMatrix(vector>& matrix, int target) { 4 | int m = matrix.size(), n = matrix[0].size(); 5 | int start = 0, end = m * n - 1; 6 | while (start <= end){ 7 | int mid = start + (end - start) / 2; 8 | int row = mid / n, col = mid % n; 9 | if (matrix[row][col] == target) 10 | return 1; 11 | else if (matrix[row][col] < target) 12 | start = mid + 1; 13 | else 14 | end = mid - 1; 15 | } 16 | return 0; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/015. Equilibrium Point/ArraySum Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> First find the sum of array. Then iterate over the array calculating the beforeSum till the current index and decrementing arraySum by the current index. If arraySum equals to beforeSum, we have got the Equilibrium Point. Else return -1. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | // Function to find equilibrium point in the array. 9 | // a: input array 10 | // n: size of array 11 | int equilibriumPoint(long long arr[], int n) { 12 | long long arrSum = 0, beforeSum = 0; 13 | for (int i = 0; i < n; i++) { 14 | arrSum += arr[i]; 15 | } 16 | for (int i = 0; i < n; i++) { 17 | arrSum -= arr[i]; 18 | if (arrSum == beforeSum) 19 | return i+1; 20 | beforeSum += arr[i]; 21 | } 22 | return -1; 23 | } 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/015. Equilibrium Point/Two Pointer Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Take 2 pointers start and end and variables before and after to store sum from 0 to start in before and n-1 to end i after. Since array has only non-negative elements, the before and after will always increase. Keep adding values in the lesser sum and if start and end point to same index and before and after have equal values, we have got our Equilibrium Point 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution{ 7 | public: 8 | // Function to find equilibrium point in the array. 9 | // a: input array 10 | // n: size of array 11 | int equilibriumPoint(long long a[], int n) { 12 | if (n == 1) return 1; 13 | long long before = a[0], after = a[n-1]; 14 | int start = 1, end = n - 2; 15 | while (start <= end) { 16 | if (before == after) { 17 | if (start == end){ 18 | return start + 1; 19 | } 20 | else{ 21 | before += a[start++]; 22 | after += a[end--]; 23 | } 24 | } 25 | else if (before < after) { 26 | before += a[start++]; 27 | } 28 | else { 29 | after += a[end--]; 30 | } 31 | } 32 | return -1; 33 | } 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/017. Find Transition Point/Binary Search Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Use Binary Search to find the index of first 1 in the given array. 3 | * Time Complexity -> O(log(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution 7 | { 8 | public: 9 | int transitionPoint(int arr[], int n) { 10 | int start = 0, end = n - 1, index = -1; 11 | while (start <= end) { 12 | int mid = start + (end - start) / 2; 13 | if (arr[mid] == 1){ 14 | index = mid; 15 | end = mid - 1; 16 | } 17 | else { 18 | start = mid + 1; 19 | } 20 | } 21 | return index; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/017. Find Transition Point/Brute Force Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Iterate over the given array and when 1 is encountered return its index, if no 1 is found return -1. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(1) 5 | */ 6 | class Solution 7 | { 8 | public: 9 | int transitionPoint(int arr[], int n) { 10 | for (int i = 0; i < n; i++) { 11 | if (arr[i] == 1) 12 | return i; 13 | } 14 | return -1; 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/018. Alternate Positive and Negative Numbers/Iterative Approach.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Approach -> Iterate over the given array and store postive and negative numbers into 2 separate arrays. Then fill the positive values at indexes divisible by 2 and odd values at indexes not divisible by 2 in the original array. Then fill remaining elements, if any. 3 | * Time Complexity -> O(N) 4 | * Space Complexity -> O(N) 5 | */ 6 | class Solution{ 7 | public: 8 | 9 | void rearrange(int arr[], int n) { 10 | vector positive, negative; 11 | for (int i = 0; i < n; i++){ 12 | if (arr[i] < 0) 13 | negative.push_back(arr[i]); 14 | else 15 | positive.push_back(arr[i]); 16 | } 17 | int index = 0, pos = 0, neg = 0; 18 | while (pos < positive.size() && neg < negative.size()){ 19 | if(index%2) 20 | arr[index++] = negative[neg++]; 21 | else 22 | arr[index++] = positive[pos++]; 23 | } 24 | while (pos < positive.size()) arr[index++] = positive[pos++]; 25 | while (neg < negative.size()) arr[index++] = negative[neg++]; 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/019. Union of Two Sorted Arrays/Two Pointer Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | //arr1,arr2 : the arrays 4 | // n, m: size of arrays 5 | //Function to return a list containing the union of the two arrays. 6 | vector findUnion(int arr1[], int arr2[], int n, int m) 7 | { 8 | vector ans; 9 | int first = 0, second = 0; 10 | while (first < n && second < m) { 11 | if (arr1[first] <= arr2[second]){ 12 | ans.push_back(arr1[first++]); 13 | } 14 | else { 15 | ans.push_back(arr2[second++]); 16 | } 17 | while (first < n && ans.back() == arr1[first]) first++; 18 | while (second < m && ans.back() == arr2[second]) second++; 19 | } 20 | while (first < n) { 21 | ans.push_back(arr1[first++]); 22 | while (first < n && ans.back() == arr1[first]) first++; 23 | } 24 | while (second < m) { 25 | ans.push_back(arr2[second++]); 26 | while (second < m && ans.back() == arr2[second]) second++; 27 | } 28 | return ans; 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/020. Three Way Partitioning/InBuilt Function Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | //Function to partition the array around the range such that array is divided into three parts. 4 | void threeWayPartition(vector& array,int a, int b) 5 | { 6 | sort(array.begin(), array.end()); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/020. Three Way Partitioning/One Pointer Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | //Function to partition the array around the range such that array is divided into three parts. 4 | void threeWayPartition(vector& array,int a, int b) 5 | { 6 | int index = 0; 7 | for (int i = 0; i < array.size(); i++) { 8 | if (array[i] < a) { 9 | swap(array[index++], array[i]); 10 | } 11 | } 12 | for (int i = index; i < array.size();i++) { 13 | if (array[i] <= b) { 14 | swap(array[index++], array[i]); 15 | } 16 | } 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/022. Min Subsets with Consecutive Numbers/Sort and Count Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int numofsubset(int arr[], int n) 4 | { 5 | int cnt = 1; 6 | sort(arr, arr+n); 7 | for (int i = 1; i < n; i++) { 8 | if (arr[i] - arr[i-1] != 1) 9 | cnt++; 10 | } 11 | return cnt; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/024. Rearrange Array Alternately/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | // This function wants you to modify the given input array and no need to return anything 4 | // arr: input array 5 | // n: size of array 6 | //Function to rearrange the array elements alternately. 7 | void rearrange(long long *arr, int n) 8 | { 9 | int mx = arr[n-1]; mx++; 10 | int start = 0, end = n - 1; 11 | for (int i = 0; i < n; i++) { 12 | if (i%2) { 13 | arr[i] += mx * (arr[start++] % mx); 14 | } 15 | else { 16 | arr[i] += mx * (arr[end--] % mx); 17 | } 18 | } 19 | for (int i = 0; i < n; i++) { 20 | arr[i] = arr[i] / mx; 21 | } 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/026. Rearrange an Array with O(1) Extra Space/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | // arr: input array // n: size of array 4 | //Function to rearrange an array so that arr[i] becomes arr[arr[i]] with O(1) extra space. 5 | void arrange(long long arr[], int n) { 6 | for (int i = 0; i < n; i++) { 7 | arr[i] += (arr[arr[i]] % n) * n; 8 | } 9 | for (int i = 0; i < n; i++) { 10 | arr[i] = arr[i] / n; 11 | } 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/027. Count Triplets with Sum smaller than X/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | long long countTriplets(long long arr[], int n, long long sum) 4 | { 5 | long long cnt = 0; 6 | sort(arr, arr+n); 7 | for (int i = 0; i < n - 2; i++) { 8 | int start = i + 1, end = n - 1; 9 | while (start < end) { 10 | if (arr[i] + arr[start] + arr[end] >= sum) 11 | end--; 12 | else 13 | cnt += end-start, start++; 14 | } 15 | } 16 | return cnt; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/029. Row with Max 1s/Binary Search Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int rowWithMax1s(vector > arr, int n, int m) { 4 | int mx = INT_MIN, index = -1; 5 | for (int i = 0; i < n; i++) { 6 | int start = 0, end = m - 1, one = m; 7 | while (start <= end) { 8 | int mid = start + (end - start) / 2; 9 | if (arr[i][mid] == 1) { 10 | one = mid; 11 | end = mid - 1; 12 | } 13 | else { 14 | start = mid + 1; 15 | } 16 | } 17 | int cnt = m - one; 18 | if (cnt && cnt > mx) { 19 | mx = cnt; 20 | index = i; 21 | } 22 | } 23 | return index; 24 | } 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/029. Row with Max 1s/Linear Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int rowWithMax1s(vector > arr, int n, int m) { 4 | int row = 0, col = m - 1, index = -1; 5 | while (row < n && col >= 0) { 6 | if (arr[row][col] == 1) 7 | index = row, col--; 8 | else 9 | row++; 10 | } 11 | return index; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /DSA Sheet/01. Array/036. Watering Plants/Solution.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int wateringPlants(vector& plants, int capacity) { 4 | int index = 0, water = capacity, steps = 0; 5 | while (index < plants.size()) { 6 | if (water < plants[index]) { 7 | water = capacity - plants[index]; 8 | steps += (index + 1) * 2 - 1; 9 | } 10 | else { 11 | water -= plants[index]; 12 | steps++; 13 | } 14 | index++; 15 | } 16 | return steps; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /DSA Sheet/Coder Army Sheet.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/DSA Sheet/Coder Army Sheet.xlsx -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/022. Binary Search with Theory and Code/Binary Search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int search(vector& nums, int target) { 4 | int start=0,end=nums.size()-1,mid; 5 | while(start<=end) 6 | { 7 | mid=start+(end-start)/2; 8 | 9 | if(nums[mid]==target) 10 | return mid; 11 | else if(nums[mid] lowercase(26,0); 5 | vector uppercase(26,0); 6 | 7 | for(int i=0;i='a') 9 | lowercase[s[i]-'a']++; 10 | else 11 | uppercase[s[i]-'A']++; 12 | } 13 | 14 | int count=0; 15 | bool odd=0; 16 | for(int i=0;i<26;i++){ 17 | if(lowercase[i]%2==0) 18 | count+=lowercase[i]; 19 | else{ 20 | count+=lowercase[i]-1; 21 | odd=1; 22 | } 23 | 24 | if(uppercase[i]%2==0) 25 | count+=uppercase[i]; 26 | else{ 27 | count+=uppercase[i]-1; 28 | odd=1; 29 | } 30 | } 31 | return count+odd; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/038. Longest Palindrome || Sorting the Sentence/2. Sorting the Sentence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string sortSentence(string s) { 4 | vector ans(10); 5 | string temp; 6 | int count=0,index=0; 7 | 8 | while(index count(256,0); 5 | int first=0,second=0,len=0; 6 | while(second count(256,0); 6 | int first=0,second=0,len=str.size(),diff=0; 7 | while(first lps(n,0); 11 | while(suffix& arr, int start, int mid, int end){ 4 | vector temp(end-start+1); 5 | int left=start, right=mid+1, index=0; 6 | while(left<=mid && right<=end){ 7 | if(arr[left]& arr, int start, int end){ 32 | if(start == end) return; 33 | int mid = start + (end - start)/2; 34 | mergeSort(arr,start,mid); 35 | mergeSort(arr,mid+1,end); 36 | merge(arr,start,mid,end); 37 | } 38 | vector sortArray(vector& nums) { 39 | mergeSort(nums,0,nums.size()-1); 40 | return nums; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/060. Quick Sort Algorithm/Quick Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int partition(int arr[], int start, int end){ 5 | int pos = start; 6 | for (int i = start; i <= end; i++) 7 | if(arr[i] <= arr[end]) 8 | swap(arr[i], arr[pos++]); 9 | return pos - 1; 10 | } 11 | void quickSort(int arr[], int start, int end){ 12 | if (start >= end) 13 | return; 14 | int pivot = partition(arr, start, end); 15 | quickSort(arr, start, pivot - 1); 16 | quickSort(arr, pivot + 1, end); 17 | } 18 | 19 | int main(){ 20 | int n=10, arr[] = {6,4,2,8,13,7,11,9,3,6}; 21 | quickSort(arr, 0, n-1); 22 | for (int i = 0; i < n; i++){ 23 | cout << arr[i] << " "; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/067. Josephus Problem || Predict the Winner/Optimized Approach.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int winner(int n, int k) { 4 | if (n == 1) { 5 | return 0; 6 | } 7 | return (winner(n-1, k) + k) % n; 8 | } 9 | 10 | int findTheWinner(int n, int k) { 11 | return winner(n, k) + 1; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/068. Recursion Rat in a Maze Problem/Rat in a Maze.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int row[4] = {1,-1,0,0}; 4 | int col[4] = {0,0,-1,1}; 5 | string dir = "DULR"; 6 | 7 | bool valid(int i, int j, int n) { 8 | return i>=0 && j>=0 && i>& matrix, int i, int j, int n, string& path, vector& ans, vector>& visited) { 12 | if (i == n-1 && j == n-1) { 13 | ans.push_back(path); 14 | return; 15 | } 16 | visited[i][j] = 1; 17 | for (int k = 0; k < 4; k++) { 18 | if (valid(i+row[k], j+col[k], n) && matrix[i+row[k]][j+col[k]] && !visited[i+row[k]][j+col[k]]) { 19 | path.push_back(dir[k]); 20 | Total(matrix, i+row[k], j+col[k], n, path, ans, visited); 21 | path.pop_back(); 22 | } 23 | } 24 | visited[i][j] = 0; 25 | } 26 | 27 | vector findPath(vector> &m, int n) { 28 | vector> visited(n, vector(n, 0)); 29 | vector ans; 30 | string path; 31 | if (m[0][0] == 0 || m[n-1][n-1] == 0) 32 | return ans; 33 | Total(m, 0, 0, n, path, ans, visited); 34 | return ans; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/081. Linked List LeetCode Problem: Remove Every Kth Node | Rotate List | Palindrome List/1. Remove Nth Node From End of List.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | class Solution { 12 | public: 13 | ListNode* removeNthFromEnd(ListNode* head, int n) { 14 | ListNode* temp = head; 15 | int count = 0; 16 | while (temp) { 17 | count++; 18 | temp = temp->next; 19 | } 20 | count -= n; 21 | if (count == 0) { 22 | temp = head; 23 | head = head->next; 24 | delete temp; 25 | } 26 | else { 27 | ListNode *curr = head, *prev = NULL; 28 | while (count--) { 29 | prev = curr; 30 | curr = curr->next; 31 | } 32 | prev->next = curr->next; 33 | delete curr; 34 | } 35 | return head; 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/081. Linked List LeetCode Problem: Remove Every Kth Node | Rotate List | Palindrome List/2. Remove every kth node.cpp: -------------------------------------------------------------------------------- 1 | /* Link list Node 2 | 3 | struct Node 4 | { 5 | int data; 6 | struct Node* next; 7 | 8 | Node(int x){ 9 | data = x; 10 | next = NULL; 11 | } 12 | 13 | }; 14 | */ 15 | 16 | /*You are required to complete this method*/ 17 | 18 | /* Function to get the middle of the linked list*/ 19 | /*K will always be in range */ 20 | 21 | class Solution { 22 | public: 23 | Node* deleteK(Node *head,int K) { 24 | if (K == 1) return NULL; 25 | Node *curr = head, *prev = NULL; 26 | int count = 1; 27 | while (curr) { 28 | if (count == K) { 29 | prev->next = curr->next; 30 | delete curr; 31 | curr = prev->next; 32 | count = 1; 33 | } 34 | else { 35 | prev = curr; 36 | curr = curr->next; 37 | count++; 38 | } 39 | } 40 | return head; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/2. Insert an Element at the Bottom of a Stack.cpp: -------------------------------------------------------------------------------- 1 | //User function Template for C++ 2 | 3 | class Solution{ 4 | public: 5 | stack insertAtBottom(stack st,int x){ 6 | stack s; 7 | while (!st.empty()) { 8 | s.push(st.top()); 9 | st.pop(); 10 | } 11 | st.push(x); 12 | while (!s.empty()) { 13 | st.push(s.top()); 14 | s.pop(); 15 | } 16 | return st; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/3. Make the array beautiful.cpp: -------------------------------------------------------------------------------- 1 | // User function Template for C++ 2 | 3 | class Solution { 4 | public: 5 | vector makeBeautiful(vector arr) { 6 | stack st; 7 | for (int i = 0; i < arr.size(); i++) { 8 | if (st.empty()) { 9 | st.push(arr[i]); 10 | } 11 | else if (arr[i] >= 0) { 12 | if (st.top() < 0) { 13 | st.pop(); 14 | } 15 | else { 16 | st.push(arr[i]); 17 | } 18 | } 19 | else { 20 | if (st.top() >= 0) { 21 | st.pop(); 22 | } 23 | else { 24 | st.push(arr[i]); 25 | } 26 | } 27 | } 28 | vector ans(st.size()); 29 | int index = st.size() - 1; 30 | while (!st.empty()) { 31 | ans[index--] = st.top(); 32 | st.pop(); 33 | } 34 | return ans; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/4. String Manipulation.cpp: -------------------------------------------------------------------------------- 1 | //User function Template for C++ 2 | 3 | class Solution{ 4 | public: 5 | int removeConsecutiveSame(vector v) 6 | { 7 | stack st; 8 | for (int i = 0; i < v.size(); i++) { 9 | if (st.empty()) { 10 | st.push(v[i]); 11 | } 12 | else if (v[i] == st.top()) { 13 | st.pop(); 14 | } 15 | else { 16 | st.push(v[i]); 17 | } 18 | } 19 | return st.size(); 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/9. Print Bracket Number.cpp: -------------------------------------------------------------------------------- 1 | //User function template for C++ 2 | class Solution{ 3 | public: 4 | 5 | vector bracketNumbers(string S) 6 | { 7 | vector ans; 8 | int count = 0; 9 | stack st; 10 | for (int i = 0; i < S.size(); i++) { 11 | if (S[i] == '(') { 12 | count++; 13 | ans.push_back(count); 14 | st.push(count); 15 | } 16 | else if (S[i] == ')') { 17 | ans.push_back(st.top()); 18 | st.pop(); 19 | } 20 | } 21 | return ans; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/98-88. Get min at pop.cpp: -------------------------------------------------------------------------------- 1 | //User function Template for C++ 2 | 3 | 4 | //Function to push all the elements into the stack. 5 | stack _push(int arr[],int n) 6 | { 7 | stack st; 8 | for (int i = 0; i < n; i++) { 9 | if (st.empty()) { 10 | st.push(arr[i]); 11 | } 12 | else { 13 | st.push(min(st.top(), arr[i])); 14 | } 15 | } 16 | return st; 17 | } 18 | 19 | //Function to print minimum value in stack each time while popping. 20 | void _getMinAtPop(stacks) 21 | { 22 | while (!s.empty()) { 23 | cout << s.top() << ' '; 24 | s.pop(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/092. Stack Problem: Largest Rectangle in Histogram | Maximal Rectangle/1. Largest Rectangle in Histogram.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int largestRectangleArea(vector& heights) { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | stack st; 7 | int index; 8 | int n = heights.size(); 9 | int ans = 0; 10 | for (int i = 0; i < n; i++) { 11 | while (!st.empty() && heights[i] < heights[st.top()]) { 12 | index = st.top(); 13 | st.pop(); 14 | if (!st.empty()) 15 | ans = max(ans, heights[index] * (i - st.top() - 1)); 16 | else 17 | ans = max(ans, heights[index] * i); 18 | } 19 | st.push(i); 20 | } 21 | while (!st.empty()) { 22 | index = st.top(); 23 | st.pop(); 24 | if (!st.empty()) 25 | ans = max(ans, heights[index] * (n - st.top() - 1)); 26 | else 27 | ans = max(ans, heights[index] * (n)); 28 | } 29 | return ans; 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/094. Stack Hard: Maximum of minimum for every window Size | Get Minimum Element from Stack/1. Get minimum element from stack.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | The structure of the class is as follows 3 | class _stack{ 4 | stack s; 5 | int minEle; 6 | public : 7 | int getMin(); 8 | int pop(); 9 | void push(int); 10 | }; 11 | */ 12 | 13 | class Solution{ 14 | int minEle; 15 | stack st; 16 | public: 17 | 18 | /*returns min element from stack*/ 19 | int getMin(){ 20 | if (st.empty()) { 21 | return -1; 22 | } 23 | else { 24 | return st.top() % 101; 25 | } 26 | } 27 | 28 | /*returns poped element from stack*/ 29 | int pop(){ 30 | if (st.empty()) { 31 | return -1; 32 | } 33 | else { 34 | int element = st.top() / 101; 35 | st.pop(); 36 | return element; 37 | } 38 | } 39 | 40 | /*push element x into the stack*/ 41 | void push(int x){ 42 | if (st.empty()) { 43 | st.push(x * 101 + x); 44 | } 45 | else { 46 | st.push(x * 101 + min(st.top() % 101, x)); 47 | } 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/097. Print all Elements in Queue | Implement Queue using Stack | Implement Stack using Queue/2. Queue Reversal.cpp: -------------------------------------------------------------------------------- 1 | //Function to reverse the queue. 2 | class Solution 3 | { 4 | public: 5 | queue rev(queue q) 6 | { 7 | stack st; 8 | while (!q.empty()) { 9 | st.push(q.front()); 10 | q.pop(); 11 | } 12 | while(!st.empty()) { 13 | q.push(st.top()); 14 | st.pop(); 15 | } 16 | return q; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/097. Print all Elements in Queue | Implement Queue using Stack | Implement Stack using Queue/3. Reverse First K elements of Queue.cpp: -------------------------------------------------------------------------------- 1 | // User function Template for C++ 2 | 3 | class Solution 4 | { 5 | public: 6 | 7 | // Function to reverse first k elements of a queue. 8 | queue modifyQueue(queue q, int k) { 9 | stack st; 10 | while (k--) { 11 | st.push(q.front()); 12 | q.pop(); 13 | } 14 | int n = q.size(); 15 | while (!st.empty()) { 16 | q.push(st.top()); 17 | st.pop(); 18 | } 19 | while (n--) { 20 | q.push(q.front()); 21 | q.pop(); 22 | } 23 | return q; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/097. Print all Elements in Queue | Implement Queue using Stack | Implement Stack using Queue/4.1 Time Needed to Buy Tickets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int timeRequiredToBuy(vector& tickets, int k) { 4 | ios::sync_with_stdio(false); 5 | cin.tie(0); 6 | int n = tickets.size(); 7 | int time = 0; 8 | queue q; 9 | for (int i = 0; i < n; i++) { 10 | q.push(i); 11 | } 12 | while (tickets[k]) { 13 | tickets[q.front()]--; 14 | if (tickets[q.front()]) { 15 | q.push(q.front()); 16 | } 17 | q.pop(); 18 | time++; 19 | } 20 | return time; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/097. Print all Elements in Queue | Implement Queue using Stack | Implement Stack using Queue/4.2 Time Needed to Buy Tickets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int timeRequiredToBuy(vector& tickets, int k) { 4 | int ans = 0; 5 | for (int i = 0; i <= k; i++) { 6 | ans += min(tickets[i], tickets[k]); 7 | } 8 | for (int i = k + 1; i < tickets.size(); i++) { 9 | ans += min(tickets[i], tickets[k] - 1); 10 | } 11 | return ans; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/098. Queues with Sliding Window Problems/2. First negative integer in every window of size k.cpp: -------------------------------------------------------------------------------- 1 | vector printFirstNegativeInteger(long long int A[], 2 | long long int N, long long int K) { 3 | vector ans; 4 | queue q; 5 | for (int i = 0; i < K - 1; i++) { 6 | if (A[i] < 0) { 7 | q.push(i); 8 | } 9 | } 10 | for (int i = K - 1; i < N; i++) { 11 | if (A[i] < 0) { 12 | q.push(i); 13 | } 14 | if (q.empty()) { 15 | ans.push_back(0); 16 | } 17 | else { 18 | if (q.front() <= i - K) { 19 | q.pop(); 20 | } 21 | if (q.empty()) { 22 | ans.push_back(0); 23 | } 24 | else { 25 | ans.push_back(A[q.front()]); 26 | } 27 | } 28 | } 29 | return ans; 30 | } 31 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/Class Illustrations/101. Introduction To Trees | Binary Tree in Data Structure/Build the Binary Tree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | class Node { 6 | public: 7 | 8 | int data; 9 | Node *left, *right; 10 | 11 | Node (int value) { 12 | data = value; 13 | left = right = NULL; 14 | } 15 | 16 | }; 17 | 18 | int main() { 19 | queue q; 20 | int x, first, second; 21 | cout << "Enter the root element : "; 22 | cin >> x; 23 | Node *root = new Node(x); 24 | q.push(root); 25 | while (!q.empty()) { 26 | Node *temp = q.front(); 27 | q.pop(); 28 | cout << "Enter the left child of " << temp->data << " : "; 29 | cin >> first; 30 | if (first != -1) { 31 | temp->left = new Node(first); 32 | q.push(temp->left); 33 | } 34 | cout << "Enter the right child of " << temp->data << " : "; 35 | cin >> second; 36 | if (second != -1) { 37 | temp->right = new Node(second); 38 | q.push(temp->right); 39 | } 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/001. Introduction To Programming for Beginners/Day 1_180 Introduction To Programming (Home work).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/001. Introduction To Programming for Beginners/Day 1_180 Introduction To Programming (Home work).pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/001. Introduction To Programming for Beginners/HomeWork Sheet Answers: -------------------------------------------------------------------------------- 1 | Introduction To Programming (Home Work) 2 | 3 | * Convert Decimal to Binary 4 | 1. 37 - 100101 5 | 2. 92 - 1011100 6 | 3. 128 - 10000000 7 | 4. 243 - 11110011 8 | 9 | * Convert Binary to Decimal 10 | 5. 1011 - 11 11 | 6. 111001 - 57 12 | 7. 10011011 - 155 13 | 8. 10100100 - 164 14 | 15 | * Convert Decimal to Octal 16 | 9. 28 - 34 17 | 10. 47 - 57 18 | 11. 928 - 1640 19 | 12. 1243 - 2333 20 | 21 | * Convert Octal to Decimal 22 | 13. 41 - 33 23 | 14. 207 - 135 24 | 15. 124 - 84 25 | 16. 311 - 201 26 | 27 | * Convert Decimal to HexaDecimal 28 | 17. 317 - 13D 29 | 18. 41 - 29 30 | 19. 14 - E 31 | 20. 845 - 34D 32 | 33 | * Convert HexaDecimal to Decimal 34 | 21. A11 - 2577 35 | 22. 49 - 73 36 | 23. AE2F - 44591 37 | 24. D97 - 3479 38 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/001. Introduction To Programming for Beginners/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 1. Introduction To Programming for Beginners 2 | Link -> https://www.youtube.com/watch?v=y3OOaXrFy-Q 3 | HomeWork Sheet -> https://docs.google.com/document/d/13tmWkludFv4dKS6tiws2zkFWJ7QLINXhVuKOzR56Jlk 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/002. Introduction to FlowCharts and PseudoCode in Programming/Day 2_180 Flowchart and PseudoCode.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/002. Introduction to FlowCharts and PseudoCode in Programming/Day 2_180 Flowchart and PseudoCode.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/002. Introduction to FlowCharts and PseudoCode in Programming/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 2. Introduction to FlowCharts and PseudoCode in Programming 2 | Link -> https://www.youtube.com/watch?v=H_9MSvTL74g 3 | HomeWork Sheet -> https://docs.google.com/document/d/1ighQuVjhWbIcBLko_l24Nn3rNch9MKxaWjKgXP2Y-OI 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/003. Start C++ from Zero and Write Your First Program/Day 3_180 Introduction to C++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/003. Start C++ from Zero and Write Your First Program/Day 3_180 Introduction to C++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/003. Start C++ from Zero and Write Your First Program/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 3. Start C++ from Zero and Write Your First Program 2 | Link -> https://www.youtube.com/watch?v=2Gexv2eld4Y 3 | HomeWork Sheet -> https://docs.google.com/document/d/12WCf8uYyC5KqhF-WvR9o0SkyvKDZlILk4z7HdhRK1T4 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/003. Start C++ from Zero and Write Your First Program/HomeWork Sheet Solutions/1. Product.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int a,b; 8 | cin>>a>>b; 9 | cout< https://www.youtube.com/watch?v=gGaJJovz-4k 3 | HomeWork Sheet -> https://docs.google.com/document/d/1RgJHduYfDV0b3fDHB17lQ_XxI9clAW1OxJSVgmW7ufw 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/004. If Else Statement in C++ || Loop in C++/HomeWork Sheet Solutions/For Loop/1. World Cup 2023.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | 8 | for(int i=1;i<=20;i++){ 9 | cout<<"India will win the World Cup 2023\n"; 10 | } 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/004. If Else Statement in C++ || Loop in C++/HomeWork Sheet Solutions/For Loop/2. Odd Numbers till N.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int n; 8 | cin>>n; 9 | 10 | for(int i=1;i<=n;i=i+2){ 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int n; 8 | cin>>n; 9 | 10 | for(int i=4;i<=n;i=i+4){ 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int a,b; 8 | cin>>a>>b; 9 | 10 | if(a>b) 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int age; 8 | cin>>age; 9 | 10 | if(age>18) 11 | cout<<"Adult"; 12 | else 13 | cout<<"Teenager"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/004. If Else Statement in C++ || Loop in C++/HomeWork Sheet Solutions/If-Else/3. Month Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int n; 8 | cin>>n; 9 | 10 | if(n==1) 11 | cout<<"January"; 12 | else if(n==2) 13 | cout<<"February"; 14 | else if(n==3) 15 | cout<<"March"; 16 | else if(n==4) 17 | cout<<"April"; 18 | else if(n==5) 19 | cout<<"May"; 20 | else if(n==6) 21 | cout<<"June"; 22 | else if(n==7) 23 | cout<<"July"; 24 | else if(n==8) 25 | cout<<"August"; 26 | else if(n==9) 27 | cout<<"September"; 28 | else if(n==10) 29 | cout<<"October"; 30 | else if(n==11) 31 | cout<<"November"; 32 | else 33 | cout<<"December"; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/004. If Else Statement in C++ || Loop in C++/HomeWork Sheet Solutions/If-Else/4. Ticket Price Calculator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int age; 8 | cin>>age; 9 | 10 | if(age<12||age>65) 11 | cout<<"YES"; 12 | else 13 | cout<<"NO"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/005. For Loop in C++ Advance || Prime Number || Factorial || Fibonacci || Sum of n number/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 5. For Loop in C++ Advance || Prime Number || Factorial || Fibonacci || Sum of n number 2 | Link -> https://www.youtube.com/watch?v=7qINbIQK_J8 3 | HomeWork Sheet -> https://docs.google.com/document/d/1bDa1qwltuAhlUWUJFh9yyvCeqlY9q6qbmWG4gYMFCKI 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/005. For Loop in C++ Advance || Prime Number || Factorial || Fibonacci || Sum of n number/HomeWork Sheet Solutions/1. 280 to 250.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int i; 8 | 9 | for(i=280;i>=250;i=i-1) 10 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | for(char name='A';name<='Z';name=name+1) 8 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | for(char name='Z';name>='A';name=name-1) 8 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | for(int i=220;i<=730;i+=7) 8 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int n,sum=0; 8 | cin>>n; 9 | 10 | for(int i=1;i<=n;i++) 11 | sum+=i*i; 12 | 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int n,sum=0; 8 | cin>>n; 9 | 10 | for(int i=1;i<=n;i++) 11 | sum+=i*i*i; 12 | 13 | cout< https://www.youtube.com/watch?v=0LawAwK5OaI 3 | HomeWork Sheet -> https://docs.google.com/document/d/1blYWqp4Gl-V8XggREHPmgCvZPwaiY5AvKvMZgN6tpdg 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/006. Solve Any Pattern Problem With Simple Trick Part-1/HomeWork Sheet Solutions/1st Pattern.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int row,col; 8 | 9 | for(row=1;row<=5;row++) 10 | { 11 | for(col=1;col<=6;col++) 12 | cout<<4<<" "; 13 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | 8 | for(int row=1;row<=6;row++) 9 | { 10 | for(int col=1;col<=5;col++) 11 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int row,col; 8 | 9 | for(row=1;row<=5;row++) 10 | { 11 | for(col=1;col<=6;col++) 12 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | 8 | for(int row=1;row<=5;row++) 9 | { 10 | for(char col='F';col<='K';col++) 11 | cout< https://docs.google.com/document/d/1v_NEofN6qPtf9b93OEsgqt2VSNGb25shtnFlpmDXdtQ 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/008. Solve HARD Pattern Print Problem with Simple Trick/Day 10_180_ Pattern Printing-2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/008. Solve HARD Pattern Print Problem with Simple Trick/Day 10_180_ Pattern Printing-2.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/008. Solve HARD Pattern Print Problem with Simple Trick/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1vWx-E-aPrplA8Mj2fqrC9v3h9BUNe0tqRAa4Sc0AfTQ 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/009. Top 5 Advance Pattern Print Problems/Day 11_180_ Pattern Printing- Super Hard.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/009. Top 5 Advance Pattern Print Problems/Day 11_180_ Pattern Printing- Super Hard.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/009. Top 5 Advance Pattern Print Problems/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1QLe7HyTguO9FKFblC3ljx5kyFWQc2ubrFCiylLArm6g 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/Day 12_180 Operator in C++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/Day 12_180 Operator in C++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 10. Operators in C++ with Implementation 2 | Link -> https://www.youtube.com/watch?v=HI0mNthclGE 3 | HomeWork Sheet -> https://docs.google.com/document/d/1mhsy7jZgajpLWgaxFuTPZC3L29lWVlPhyHpLqjr4tmk 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/HomeWork Sheet Solutions/1. Temperature Range.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int temp; 8 | cin>>temp; 9 | 10 | if(temp>70&&temp<90) 11 | cout<<"Yes"; 12 | else 13 | cout<<"No"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/HomeWork Sheet Solutions/2. Even and Positive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int n; 8 | cin>>n; 9 | 10 | if(n>0&&n%2==0) 11 | cout<<"Yes"; 12 | else 13 | cout<<"No"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/HomeWork Sheet Solutions/3. Age Check.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int age; 8 | cin>>age; 9 | 10 | if(age>=13&&age<=19) 11 | cout<<"Yes"; 12 | else 13 | cout<<"No"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/010. Operators in C++ with Implementation/HomeWork Sheet Solutions/4. Either Greater.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | ios::sync_with_stdio(false); 6 | cin.tie(0);cout.tie(0); 7 | int a,b,c; 8 | cin>>a>>b>>c; 9 | 10 | if(a>b || a>c) 11 | cout<<"Yes"; 12 | else 13 | cout<<"No"; 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/011. While and Do While Loop || Switch || Break || Continue in C++/Day 15_180 While, do While , Switch c++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/011. While and Do While Loop || Switch || Break || Continue in C++/Day 15_180 While, do While , Switch c++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/011. While and Do While Loop || Switch || Break || Continue in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1j3UjLp_RgssJKvv_q3o8nkA1GCWza8VoMz_KV9oxkLg 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/012. Binary To Decimal || Decimal To Binary || Decimal To Octal || Binary To Octal Conversion/Day 16_180 Binary to Decimal Conversion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/012. Binary To Decimal || Decimal To Binary || Decimal To Octal || Binary To Octal Conversion/Day 16_180 Binary to Decimal Conversion.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/012. Binary To Decimal || Decimal To Binary || Decimal To Octal || Binary To Octal Conversion/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1y99g1CKntvtypPAIfpbNYvrgy1LLZta87SpC3lj8W8c 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/013. Write Your First Program On LeetCode/Day 17_180 - Sheet1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/013. Write Your First Program On LeetCode/Day 17_180 - Sheet1.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/013. Write Your First Program On LeetCode/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/spreadsheets/d/1ivpxIYXZ8p4geJpxFN9Q0hVEnFu0O4FaSPumDqNLw30 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/014. Functions in C++ || Pass by Value || Pass by Reference/Day 18_180 Function in C++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/014. Functions in C++ || Pass by Value || Pass by Reference/Day 18_180 Function in C++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/014. Functions in C++ || Pass by Value || Pass by Reference/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 014. Functions in C++ || Pass by Value || Pass by Reference 2 | Link -> https://www.youtube.com/watch?v=PnSgN5WOUC0 3 | HomeWork Sheet -> https://docs.google.com/document/d/1JvmIq6O2quiCB_eH-P5VaqQXTIctsR0tq91bbXWVS_8 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/014. Functions in C++ || Pass by Value || Pass by Reference/HomeWork Sheet Solutions/1. Cube.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int Cube (int n) 4 | { 5 | return (n*n*n); 6 | } 7 | 8 | int main() 9 | { 10 | ios::sync_with_stdio(false); 11 | cin.tie(0);cout.tie(0); 12 | int num; 13 | cin>>num; 14 | 15 | int ans=Cube(num); 16 | cout< 2 | using namespace std; 3 | int Reverse (int n) 4 | { 5 | int rem,ans=0; 6 | while(n) { 7 | rem=n%10; 8 | n/=10; 9 | ans=ans*10+rem; 10 | } 11 | return ans; 12 | } 13 | 14 | int main() 15 | { 16 | ios::sync_with_stdio(false); 17 | cin.tie(0);cout.tie(0); 18 | int n; 19 | cin>>n; 20 | cout< 2 | using namespace std; 3 | int Swap3 (int &a, int &b, int &c) 4 | { 5 | c=a+b+c; 6 | a=c-(a+b); 7 | b=c-(a+b); 8 | c=c-(a+b); 9 | } 10 | 11 | int main() 12 | { 13 | ios::sync_with_stdio(false); 14 | cin.tie(0);cout.tie(0); 15 | int a,b,c; 16 | cin>>a>>b>>c; 17 | Swap3(a,b,c); 18 | cout< 2 | using namespace std; 3 | int Swap (int &a, int &b) 4 | { 5 | a=a+b; 6 | b=a-b; 7 | a=a-b; 8 | } 9 | int main() 10 | { 11 | ios::sync_with_stdio(false); 12 | cin.tie(0);cout.tie(0); 13 | int a,b; 14 | cin>>a>>b; 15 | Swap(a,b); 16 | cout< https://docs.google.com/document/d/1yrDu7dHptFsQ6k84qW_Q9EvvR5fyBKpyz0lBk_NsEVk 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/016. Introduction To Arrays in C++/Day 22_180 Introduction to Arrays in c++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/016. Introduction To Arrays in C++/Day 22_180 Introduction to Arrays in c++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/016. Introduction To Arrays in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 016. Introduction To Arrays in C++ 2 | Link -> https://www.youtube.com/watch?v=moZNKL37w-s 3 | HomeWork Sheet -> https://docs.google.com/document/d/1a1ksRBwXyhZQWNxIb2SeiGkbzO0xTES50fjd9bAiOh8 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/017. Master Arrays By Solving Problems/Day 23_180 Master arrays by solving Problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/017. Master Arrays By Solving Problems/Day 23_180 Master arrays by solving Problem.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/017. Master Arrays By Solving Problems/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | 017. Master Arrays By Solving Problems 2 | Link -> https://www.youtube.com/watch?v=567332frcF0 3 | HomeWork Sheet -> https://docs.google.com/document/d/1s-dpoMhDklam2_IMSBZrKlgvLqN2KdfoAloBclxaOsE 4 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/017. Master Arrays By Solving Problems/HomeWork Sheet Solutions/2. Move all Negative Elements to End.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | void segregateElements(int arr[],int n) 4 | { 5 | int p=0,positive[100000],N=0,negative[100000]; 6 | for(int i=0;i-0) 8 | { 9 | positive[p]=arr[i]; 10 | p++; 11 | } 12 | else 13 | { 14 | negative[N]=arr[i]; 15 | N++; 16 | } 17 | } 18 | 19 | for(int i=0;ix) break; 10 | } 11 | return occurs; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/017. Master Arrays By Solving Problems/HomeWork Sheet Solutions/4. Count Number of Elements between Two given Elements in Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int getCount(int arr[], int n, int num1, int num2) 4 | { 5 | //Complete the function 6 | int index1=-1, index2=-1; 7 | for(int i=0;i& nums) { 4 | int n=nums.size(); 5 | int sum=0; 6 | for(int i=0;i https://docs.google.com/document/d/1IumCatcUeGZRDjBiOv5mDDkMFtGWAYsuJks07u-HtdA 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/019. SELECTION SORT Algorithm with Theory and Code/Day 25_180 Selection Sort in C++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/019. SELECTION SORT Algorithm with Theory and Code/Day 25_180 Selection Sort in C++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/019. SELECTION SORT Algorithm with Theory and Code/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/14TV28QgSnQF4BhO_TM49conJjKoXHpQzD03AIZ2zJuI/edit 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/019. SELECTION SORT Algorithm with Theory and Code/HomeWork Sheet Solutions/1. Decreasing Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | for(int i=0;iarr[index]) 18 | index=j; 19 | } 20 | swap(arr[i],arr[index]); 21 | } 22 | 23 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | for(int i=n-1;i>0;i--){ 15 | int index=i; 16 | for(int j=i-1;j>=0;j--){ 17 | if(arr[j]>arr[index]) 18 | index=j; 19 | } 20 | swap(arr[i],arr[index]); 21 | } 22 | 23 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | char arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | for(int i=0;i https://docs.google.com/document/d/1f4FJizRZmDRHXHUg8AdADQTrtoI2nJf5faXY2qVvg5I 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/020. Bubble Sort with Theory and Code/HomeWork Sheet Solutions/1. Decreasing Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | for(int i=n-1;i>0;i--){ 15 | bool swapped=0; 16 | for(int j=0;j https://docs.google.com/document/d/1_5x8khzxdOksrRs3eHLFXwODUBVOPB2QhmG9IU9KsTA 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/021. Insertion Sort with Theory and Code/HomeWork Sheet Solutions/1. Decreasing Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | for(int i=1;i0;j--){ 16 | if(arr[j]>arr[j-1]) 17 | swap(arr[j],arr[j-1]); 18 | else 19 | break; 20 | } 21 | } 22 | 23 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | for(int i=n-2;i>=0;i--){ 15 | for(int j=i;jarr[j+1]) 17 | swap(arr[j],arr[j+1]); 18 | else 19 | break; 20 | } 21 | } 22 | 23 | for(int i=0;i https://docs.google.com/document/d/1ONZ4LKLO2eZ8K7o-8OcRuFQ21nNinlhieIkpyZZNONs 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/022. Binary Search with Theory and Code/HomeWork Sheet Solutions/1. Search in Decreasing Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int arr[100]; 9 | int n; 10 | cin>>n; 11 | 12 | for(int i=0;i>arr[i]; 13 | 14 | int key,index=-1; 15 | cin>>key; 16 | 17 | int start=0,end=n-1,mid; 18 | while(start<=end){ 19 | mid=start+(end-start)/2; 20 | if(arr[mid]==key){ 21 | index=mid; 22 | break; 23 | } 24 | else if(arr[mid]>key) 25 | start=mid+1; 26 | else 27 | end=mid-1; 28 | } 29 | cout<& arr, int key) { 4 | int n=arr.size(); 5 | int start=0,end=n-1,mid; 6 | 7 | while(start<=end){ 8 | mid=start+(end-start)/2; 9 | if(arr[mid]==key) 10 | return mid; 11 | else if(arr[mid] https://docs.google.com/document/d/1-Z7evcSzBfGeROWTDZajupsD6z6IFC0ZFp5LruDluaw 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/024. Binary Search Problem Solving-2/Day 32_180 Binary Search Problem Part 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/024. Binary Search Problem Solving-2/Day 32_180 Binary Search Problem Part 2.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/024. Binary Search Problem Solving-2/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1uE11p-D-SpaFKWlmProc9A_HZhb3ABL77795NOdXGzU 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/025. Binary Search Top Interview Problem || Book Allocation || Painter Partition || Ship Package/Day 33_180 Binary Search Interview Problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/025. Binary Search Top Interview Problem || Book Allocation || Painter Partition || Ship Package/Day 33_180 Binary Search Interview Problem.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/025. Binary Search Top Interview Problem || Book Allocation || Painter Partition || Ship Package/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1ie1Xl1tl1y5HE6z7WBXkStaivezRmh8jO_4hvuRk67M 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/026. Binary Search Hard Interview Problem || Aggressive Cow || KOKO Eating Banana/Day 36_180 Binary Search Hard Interview Problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/026. Binary Search Hard Interview Problem || Aggressive Cow || KOKO Eating Banana/Day 36_180 Binary Search Hard Interview Problem.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/026. Binary Search Hard Interview Problem || Aggressive Cow || KOKO Eating Banana/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1mzAkslYetXyZeIIVcKvCaOKlxED6GPBsD-czhd9zULQ/edit 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/027. What is STL || Vector in C++/Day 37_180 Vector in C++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/027. What is STL || Vector in C++/Day 37_180 Vector in C++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/027. What is STL || Vector in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1dJwvWCOksD5ixnyOllSikarOM5-39Sy09pVrhXyslQw 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/027. What is STL || Vector in C++/HomeWork Sheet Solutions/1. Proof of Average Time Complexity of push_back() Operation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/027. What is STL || Vector in C++/HomeWork Sheet Solutions/1. Proof of Average Time Complexity of push_back() Operation.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/027. What is STL || Vector in C++/HomeWork Sheet Solutions/2. Number of Occurrences.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | vector v={7,1,7,7,2,3,7}; 9 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | vector v={13,8,7,9}; 9 | int maximum = *max_element(v.begin(),v.end()); 10 | cout << maximum; 11 | cout < 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | vector v={1,2,2,2,3,3}; 9 | cout< 2 | using namespace std; 3 | 4 | void fun(vector &v) 5 | { 6 | v.push_back(7); 7 | } 8 | int main() 9 | { 10 | ios::sync_with_stdio(false); 11 | cin.tie(0);cout.tie(0); 12 | vector vect; 13 | vect.push_back(13); 14 | fun(vect); 15 | for(int i: vect) 16 | cout< 2 | using namespace std; 3 | 4 | void fun(vector v) 5 | { 6 | v.push_back(13); 7 | } 8 | int main() 9 | { 10 | ios::sync_with_stdio(false); 11 | cin.tie(0);cout.tie(0); 12 | vector vect; 13 | vect.push_back(7); 14 | fun(vect); 15 | for(int i: vect) 16 | cout< https://docs.google.com/document/d/1ixXo3c5UVRa0fSYHI5hoJLTmsbVgASYxPQpywYLRJqc 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/029. Kadane's Algorithm || Prefix and Suffix Sum || Array into 2 equal Sum Subarray/Day 39_180 Kadane’s Algorithm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/029. Kadane's Algorithm || Prefix and Suffix Sum || Array into 2 equal Sum Subarray/Day 39_180 Kadane’s Algorithm.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/029. Kadane's Algorithm || Prefix and Suffix Sum || Array into 2 equal Sum Subarray/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1HiJPIox88th4izuDq70B27s38ePj_QXfG9rkPfVZfgQ 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/030. Trapping Rain Water || 3 SUM || 4 SUM/Day 40_180 Trapping Rain water.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/030. Trapping Rain Water || 3 SUM || 4 SUM/Day 40_180 Trapping Rain water.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/030. Trapping Rain Water || 3 SUM || 4 SUM/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1S2zwDs59nGN8dBKrLKa2h2F9LXEZqFPxLHD0RsNoyWE 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/031. 2D Arrays in C++/Day 43_180 Introduction to 2D array in c++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/031. 2D Arrays in C++/Day 43_180 Introduction to 2D array in c++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/031. 2D Arrays in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1aJ8_lp8c8onGrR-NEIgYJKrUSVNsayqHk3vexJxYuuw 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/031. 2D Arrays in C++/HomeWork Sheet Solutions/1. Sum ColumnWise.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | 9 | int row=3,col=4,arr[3][4]={1,2,3,4,5,6,7,8,9,10,11,12}; 10 | for(int j=0;j 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int n=3,sum=0,Sum=0; 9 | int matrix[n][n]={1,2,3,4,5,6,7,8,9}; 10 | 11 | /*Method-1*/ 12 | for(int row=0;row 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int row=3,col=4; 9 | int arr[3][4]={12,13,6,7,9,10,11,1,3,2,4,5}; 10 | int maxi = INT_MIN; 11 | 12 | for(int i=0;imaxi){ 15 | maxi=arr[i][j]; 16 | } 17 | } 18 | } 19 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int row=3,col=4; 9 | int arr[3][4]={12,13,6,7,9,10,11,1,3,2,4,5}; 10 | int mini = INT_MAX; 11 | 12 | for(int i=0;i https://docs.google.com/document/d/19rYv9cOckwMTnjKFzRfUK2HCj0HiDHtbUQCG7eJxzX0 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/032. 2D Arrays Interview Problems || Wave Form || Spiral Form || Transpose Matrix || Column Major Order/HomeWork Sheet Solutions/1. Transpose of Matrix.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | //Function to find transpose of a matrix. 5 | void transpose(vector >& matrix, int n) 6 | { 7 | for(int row=0;row 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | ios::sync_with_stdio(false); 7 | cin.tie(0);cout.tie(0); 8 | int n=3,m=3; 9 | int matrix[n][m]={1,2,3,4,5,6,7,8,9}; 10 | 11 | for(int col=0;col spiralOrder(vector>& matrix) { 4 | vector ans; 5 | int row=matrix.size(); 6 | int col=matrix[0].size(); 7 | int top=0,bottom=row-1,left=0,right=col-1; 8 | 9 | while(top<=bottom && left<=right){ 10 | for(int j=left;j<=right;j++) 11 | ans.push_back(matrix[top][j]); 12 | top++; 13 | for(int i=top;i<=bottom;i++) 14 | ans.push_back(matrix[i][right]); 15 | right--; 16 | if(top<=bottom){ 17 | for(int j=right;j>=left;j--) 18 | ans.push_back(matrix[bottom][j]); 19 | bottom--; 20 | } 21 | if(left<=right){ 22 | for(int i=bottom;i>=top;i--) 23 | ans.push_back(matrix[i][left]); 24 | left++; 25 | } 26 | } 27 | 28 | return ans; 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/032. 2D Arrays Interview Problems || Wave Form || Spiral Form || Transpose Matrix || Column Major Order/HomeWork Sheet Solutions/4. Spiral Matrix II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> generateMatrix(int n) { 4 | vector > Matrix(n,vector(n)); 5 | int top=0,bottom=n-1,left=0,right=n-1,cnt=1; 6 | while(top <= bottom && left<= right){ 7 | for(int j=left;j<=right;j++) 8 | Matrix[top][j]=cnt++; 9 | top++; 10 | for(int i=top;i<=bottom;i++) 11 | Matrix[i][right]=cnt++; 12 | right--; 13 | if(top<=bottom){ 14 | for(int j=right;j>=left;j--) 15 | Matrix[bottom][j]=cnt++; 16 | bottom--; 17 | } 18 | if(left<=right){ 19 | for(int i=bottom;i>=top;i--) 20 | Matrix[i][left]=cnt++; 21 | left++; 22 | } 23 | } 24 | return Matrix; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/032. 2D Arrays Interview Problems || Wave Form || Spiral Form || Transpose Matrix || Column Major Order/HomeWork Sheet Solutions/5. Print Diagonally.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | vector downwardDiagonal(int N, vector> A) 4 | { 5 | vector ans; 6 | int sum=0; 7 | for(int top=0;top=0){ 10 | ans.push_back(A[row][col]); 11 | row++,col--; 12 | } 13 | sum++; 14 | } 15 | for(int right=1;right=0){ 18 | ans.push_back(A[row][col]); 19 | row++,col--; 20 | } 21 | sum++; 22 | } 23 | 24 | return ans; 25 | } 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/032. 2D Arrays Interview Problems || Wave Form || Spiral Form || Transpose Matrix || Column Major Order/HomeWork Sheet Solutions/7. Print Matrix in Snake Pattern.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: /*Function to return list of integers visited in snake pattern in matrix.*/ 4 | vector snakePattern(vector > matrix) 5 | { 6 | int n=matrix.size(); 7 | vector ans; 8 | for(int row=0;row=0;col--) 14 | ans.push_back(matrix[row][col]); 15 | } 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/033. Rotate Image | Rotate by 90 degree | Rotate Matrix Element Clockwise | Rotate Matrix by 180 Degree/Day 45_180 Rotate Matrix in C++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/033. Rotate Image | Rotate by 90 degree | Rotate Matrix Element Clockwise | Rotate Matrix by 180 Degree/Day 45_180 Rotate Matrix in C++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/033. Rotate Image | Rotate by 90 degree | Rotate Matrix Element Clockwise | Rotate Matrix by 180 Degree/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1100Lb64hN3mm1TP2vCoeYvYyrwyBB0KS0OqthOsUx2E 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/033. Rotate Image | Rotate by 90 degree | Rotate Matrix Element Clockwise | Rotate Matrix by 180 Degree/HomeWork Sheet Solutions/1. Rotate Image.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void rotate(vector>& matrix) { 4 | int n=matrix.size(); 5 | for(int i=0;i >& matrix) { 4 | int n=matrix.size(); 5 | for(int i=0;i >& matrix, int n) 6 | { 7 | for(int i=0;i https://docs.google.com/document/d/1pOWds18hkD_k1E4x83Ocup-aaCdVq7a9rElMnWYDL4I 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/034. Binary Search in 2D Arrays || Search in a sorted row-col wise Matrix/HomeWork Sheet Solutions/1. Binary Search.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool searchMatrix(vector>& matrix, int target) { 4 | int n=matrix.size(),m=matrix[0].size(); 5 | int start=0,end=m*n-1,mid,row_index,col_index; 6 | 7 | while(start<=end){ 8 | mid=start+(end-start)/2; 9 | row_index=mid/m; 10 | col_index=mid%m; 11 | 12 | if(matrix[row_index][col_index]==target) 13 | return 1; 14 | else if(matrix[row_index][col_index] > matrix, int n, int m, int x) 5 | { 6 | int i=0,j=m-1; 7 | while(i=0){ 8 | if(matrix[i][j]==x){ 9 | return 1; 10 | } 11 | else if(matrix[i][j]>A) 5 | { 6 | int n=A.size(); 7 | int i=0,j=n-1,ans=0; 8 | while(i=0){ 9 | if(A[i][j]==0){ 10 | ans+=j+1; 11 | i++; 12 | } 13 | else 14 | j--; 15 | } 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/035. Solving Hard Problems On Arrays With Simple Logic || Majority Elements || Count Frequency of Element/Day 47_180 Solving Hard Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/035. Solving Hard Problems On Arrays With Simple Logic || Majority Elements || Count Frequency of Element/Day 47_180 Solving Hard Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/035. Solving Hard Problems On Arrays With Simple Logic || Majority Elements || Count Frequency of Element/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/14NS76IzocqVQoaDF2_oxJIA-WXbC-UkOQ2HnK-F3ptE 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/035. Solving Hard Problems On Arrays With Simple Logic || Majority Elements || Count Frequency of Element/HomeWork Sheet Solutions/1. Finding Missing and Repeating Elements.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | vector findTwoElement(vector arr, int n) { 4 | vector ans(2); 5 | for(int i=0;i& arr,int N, int P) 5 | { 6 | for(int i=0;i& nums) { 4 | int n=nums.size(); 5 | int candidate,count=0; 6 | for(int i=0;isize/2?candidate:-1; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/035. Solving Hard Problems On Arrays With Simple Logic || Majority Elements || Count Frequency of Element/HomeWork Sheet Solutions/4. Smallest Missing Positive Integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int firstMissingPositive(vector& arr) { 4 | int n=arr.size(); 5 | bool one=false; 6 | 7 | for(int i=0;in) 9 | arr[i]=0; 10 | else if(arr[i]==1){ 11 | arr[i]--; 12 | one=true; 13 | } 14 | else 15 | arr[i]--; 16 | } 17 | 18 | if(!one) return 1; 19 | 20 | for(int i=0;i alphabet(26,0); 5 | for(int i=0;i lowercase(26,0); 5 | vector uppercase(26,0); 6 | 7 | for(int i=0;i='a') 9 | lowercase[s[i]-'a']++; 10 | else 11 | uppercase[s[i]-'A']++; 12 | } 13 | 14 | int count=0; 15 | bool odd=0; 16 | for(int i=0;i<26;i++){ 17 | if(lowercase[i]%2==0) 18 | count+=lowercase[i]; 19 | else{ 20 | count+=lowercase[i]-1; 21 | odd=1; 22 | } 23 | 24 | if(uppercase[i]%2==0) 25 | count+=uppercase[i]; 26 | else{ 27 | count+=uppercase[i]-1; 28 | odd=1; 29 | } 30 | } 31 | return count+odd; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/038. Longest Palindrome || Sorting the Sentence/HomeWork Sheet Solutions/2. Sorting the Sentence.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string sortSentence(string s) { 4 | vector ans(10); 5 | string temp; 6 | int count=0,index=0; 7 | 8 | while(index=0){ 9 | sum=(num1[index1]-'0')+(num2[index2]-'0')+carry; 10 | carry=sum/10; 11 | char c='0'+sum%10; 12 | ans+=c; 13 | index1--,index2--; 14 | } 15 | while(index1>=0){ 16 | sum=(num1[index1]-'0')+carry; 17 | carry=sum/10; 18 | char c='0'+sum%10; 19 | ans+=c; 20 | index1--; 21 | } 22 | if(carry) ans+='1'; 23 | reverse(ans.begin(),ans.end()); 24 | return ans; 25 | } 26 | 27 | string addStrings(string num1, string num2) { 28 | if(num1.size() upper(26,0); 5 | vector lower(26,0); 6 | 7 | for(int i=0;i upper(26,0),lower(26,0); 8 | for(int i=0;i='a') 10 | lower[str[i]-'a']++; 11 | else 12 | upper[str[i]-'A']++; 13 | } 14 | for(int i=0;i='a'){ 16 | for(int j=0;j<26;j++){ 17 | if(lower[j]){ 18 | str[i]='a'+j; 19 | lower[j]--; 20 | break; 21 | } 22 | } 23 | } 24 | else{ 25 | for(int j=0;j<26;j++){ 26 | if(upper[j]){ 27 | str[i]='A'+j; 28 | upper[j]--; 29 | break; 30 | } 31 | } 32 | } 33 | } 34 | return str; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/040. Factorial of Large Number || Integer to Roman || Roman to Integer/HomeWork Sheet Solutions/2. Integer to Roman.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string intToRoman(int num) { 4 | string ones[]={"","I","II","III","IV","V","VI","VII","VIII","IX"}; 5 | string tens[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"}; 6 | string hundreds[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"}; 7 | string thousands[]={"","M","MM","MMM"}; 8 | return(thousands[num/1000]+hundreds[(num/100)%10]+tens[(num%100)/10]+ones[num%10]); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/040. Factorial of Large Number || Integer to Roman || Roman to Integer/HomeWork Sheet Solutions/3. Roman to Integer.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int num(char c){ 4 | if(c=='I') return 1; 5 | else if(c=='V') return 5; 6 | else if(c=='X') return 10; 7 | else if(c=='L') return 50; 8 | else if(c=='C') return 100; 9 | else if(c=='D') return 500; 10 | else return 1000; 11 | } 12 | 13 | int romanToInt(string s) { 14 | int sum=0,index=0; 15 | while(index https://docs.google.com/document/d/1lGykYolOyQeJ0mF1mQYG-lHwa4PQA45raI12xlQr8RE 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/041. Sliding Window Protocol on Strings/HomeWork Sheet Solutions/1. Longest Substring Without Repeating Characters.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lengthOfLongestSubstring(string s) { 4 | vector count(256,0); 5 | int first=0,second=0,len=0; 6 | while(second count(256,0); 6 | int first=0,second=0,len=str.size(),diff=0; 7 | while(first count(256,0); 5 | int first=0,second=0,found=0,len=-1; 6 | while(secondcount(256,0); 5 | int len=-1,unique=0,first=0,second=0; 6 | while(secondk){ 17 | if(count[s[first]]==1) 18 | unique--; 19 | count[s[first]]--; 20 | first++; 21 | } 22 | } 23 | return len; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/041. Sliding Window Protocol on Strings/HomeWork Sheet Solutions/Day_57_180_Sliding_window_problem_on_String.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/041. Sliding Window Protocol on Strings/HomeWork Sheet Solutions/Day_57_180_Sliding_window_problem_on_String.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/042. KMP Algorithm || Longest Prefix Suffix/Day 58_180 KMP Algorithm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/042. KMP Algorithm || Longest Prefix Suffix/Day 58_180 KMP Algorithm.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/042. KMP Algorithm || Longest Prefix Suffix/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1Huc6_2YFggr0F91UcFyvPVsR-uKIxdZpzm6fwyogvMo 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/042. KMP Algorithm || Longest Prefix Suffix/HomeWork Sheet Solutions/1. Longest Prefix Suffix.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int lps(string s) { 4 | vector lps(s.size(),0); 5 | int prefix=0,suffix=1; 6 | while(suffix lps(n+h,0); 7 | int prefix=0,suffix=1; 8 | while(suffix https://docs.google.com/document/d/1JbBtEY40bKvCk3LV-ISJQM_4B5kwoLhZpnXqIAYF0uc 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/043. String Matching || KMP Algorithm/HomeWork Sheet Solutions/1. Find the Index of the First Occurrence in a String.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void lpsfind(vector&lps,string s){ 4 | int prefix=0,suffix=1; 5 | while(suffix lps(needle.size(),0); 21 | lpsfind(lps,needle); 22 | int first=0,second=0; 23 | while(first https://docs.google.com/document/d/1b7fLWiiMYYmqJSWaCUN_NCtgcQscR1mRZIsNykwtpHE 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/044. Strings HARD Problems For Coding Round/HomeWork Sheet Solutions/1. Minimum Characters to be added at front to make String Palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minChar(string str){ 4 | int size=str.size(); 5 | string rev=str; 6 | reverse(rev.begin(),rev.end()); 7 | str+='$'; 8 | str+=rev; 9 | int prefix=0,suffix=1,n=str.size(); 10 | vector lps(n,0); 11 | while(suffix lps(n,0); 11 | while(suffix https://docs.google.com/document/d/1_I5-uLjfk0FJGGd7GNlmRhT7IJUKICLbaXVikPZt5HU 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/046. Pointers Relationship with array || Arithmetic Pointers/Day 64_180 Pointers Arithmetic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/046. Pointers Relationship with array || Arithmetic Pointers/Day 64_180 Pointers Arithmetic.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/046. Pointers Relationship with array || Arithmetic Pointers/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1gysn0lihkjwL90rn06RqTJ7YAdmm2LvGg8ZAxvbEbn0 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/047. Pointers with Character Arrays and Functions/Day 65_180 Pointers with Character Arrays and Functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/047. Pointers with Character Arrays and Functions/Day 65_180 Pointers with Character Arrays and Functions.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/047. Pointers with Character Arrays and Functions/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1WLkXpW2qWthMEgrU--G9w4fS1pp_yE7Nb7m4cdLVAQ8 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/048. Double Pointer and Multiple Pointers in C++/Day 66_180 Double Pointer in c++.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/048. Double Pointer and Multiple Pointers in C++/Day 66_180 Double Pointer in c++.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/048. Double Pointer and Multiple Pointers in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1SvTBPzz4WCWSQhwmkmR-7alAoIqCQ9VnYOd_iobLe3s 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/050. Dynamic Memory Allocation of 2D and 3D Arrays in C++/Day 71_180 Dynamic Memory Allocation of 2D and 3D Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/050. Dynamic Memory Allocation of 2D and 3D Arrays in C++/Day 71_180 Dynamic Memory Allocation of 2D and 3D Arrays.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/050. Dynamic Memory Allocation of 2D and 3D Arrays in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1VDGxA2n-fUqRApYPm0uCQpPKiPQc9FKuVPgBPx2xDLs 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/050. Dynamic Memory Allocation of 2D and 3D Arrays in C++/HomeWork Sheet Solutions/2. Deallocate 3D Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int L,B,H; 7 | cin>>L>>B>>H; 8 | /* Create 3D Array */ 9 | int ***ptr=new int **[B]; 10 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int X,L,B,H; 7 | cin>>X>>L>>B>>H; 8 | /* Create 4D Array */ 9 | int ****ptr=new int***[X]; 10 | for(int i=0;i https://docs.google.com/document/d/1i3NCiFKN9Bl3tkXW2zoXzE8h0nJ0WCKv4uGnk5wUxz4 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/051. Introduction To Recursion From Basic To Advance/HomeWork Sheet Solutions/1. Coder Army.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print(int n) 5 | { 6 | if(n==1){ /*Base Case*/ 7 | cout<<"Coder Army"< 2 | using namespace std; 3 | void printodd(int n) 4 | { 5 | if(n==1){ 6 | cout<<1<>n; if(n%2==0) n--; /*If n is EVEN, make it ODD.*/ 16 | printodd(n); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/051. Introduction To Recursion From Basic To Advance/HomeWork Sheet Solutions/3. Numbers from 1 to N.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void print(int n) 4 | { 5 | if(n==1){ 6 | cout<<1<>n; 16 | print(n); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/051. Introduction To Recursion From Basic To Advance/HomeWork Sheet Solutions/Solution_of_Day_72_180_Introduction_to_Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/051. Introduction To Recursion From Basic To Advance/HomeWork Sheet Solutions/Solution_of_Day_72_180_Introduction_to_Recursion.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/052. How To Solve Recursion Problem from 4 Different Method/Day 73_180 Solving Recursion From 4 Method.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/052. How To Solve Recursion Problem from 4 Different Method/Day 73_180 Solving Recursion From 4 Method.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/052. How To Solve Recursion Problem from 4 Different Method/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1BzXvbAbFf0elb5BzbFj8AmkM6nK3kxPxwWLvxaPtlEk 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/052. How To Solve Recursion Problem from 4 Different Method/HomeWork Sheet Solutions/1. Odd Numbers from 1 to N.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void printOdd(int n) 4 | { 5 | if(n==1){ 6 | cout<<1<>n; 15 | if(n%2==0) n--; 16 | printOdd(n); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/052. How To Solve Recursion Problem from 4 Different Method/HomeWork Sheet Solutions/2. Numbers from 10 to N.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void print(int n) 4 | { 5 | if(n==10){ 6 | cout<<10<>n; 16 | print(n); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/052. How To Solve Recursion Problem from 4 Different Method/HomeWork Sheet Solutions/3. Table of n.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void table(int n,int i=1) 4 | { 5 | if(i==10){ 6 | cout< https://docs.google.com/document/d/1aM7Z9bGbh-otGxRtYddXkHCJgp-8oyPlaX1FCsw6p4w 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/055. Recursion in Arrays/Day 78_180 Recursion in Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/055. Recursion in Arrays/Day 78_180 Recursion in Arrays.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/055. Recursion in Arrays/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1lzUIXHtk7LnExRm1w01xwLbGURZV7eXUHDsGgOTw3DY 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/055. Recursion in Arrays/HomeWork Sheet Solution/1. Maximum Element.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int maxElement(int arr[],int index) 5 | { 6 | if(index==0) 7 | { 8 | return arr[index]; 9 | } 10 | return max(arr[index],maxElement(arr,index-1)); 11 | } 12 | 13 | int main() 14 | { 15 | int n=5,arr[]={3,4,8,1,2}; 16 | cout< 2 | using namespace std; 3 | 4 | int product(int arr[],int index) 5 | { 6 | if(index==0) 7 | { 8 | return arr[index]; 9 | } 10 | return arr[index]*product(arr,index-1); 11 | } 12 | 13 | int main() 14 | { 15 | int n=5,arr[]={3,4,8,1,2}; 16 | cout< 2 | using namespace std; 3 | int NoOfEven(int arr[],int index) 4 | { 5 | if(index==-1) 6 | return 0; 7 | if(arr[index]%2) 8 | return NoOfEven(arr,index-1); 9 | else 10 | return 1+NoOfEven(arr,index-1); 11 | } 12 | 13 | int main() 14 | { 15 | int n=5,arr[]={3,4,8,1,2}; 16 | cout< https://docs.google.com/document/d/1GmBtnRi9jvQOzRnfW0slgXu9DRsxdVZM-kB-N5tPJkY 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/056. Recursion in Strings/HomeWork Sheet Solutions/1. Check Palindrome.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | 4 | 5 | int isPalindrome(string& S, int start = 0, int end = -1) 6 | { 7 | if (end == -1) end = S.size() - 1; 8 | 9 | if(start >= end) 10 | return 1; 11 | 12 | if (S[start] != S[end]) 13 | return 0; 14 | 15 | return isPalindrome(S, start+1, end-1); 16 | } 17 | 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/056. Recursion in Strings/HomeWork Sheet Solutions/2. Lower Case to Upper Case.cpp: -------------------------------------------------------------------------------- 1 | string to_upper(string str) 2 | { 3 | if(str.size()==0) return ""; 4 | char c=str.back()-'a'+'A'; 5 | str.pop_back(); 6 | return to_upper(str)+c; 7 | } 8 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/056. Recursion in Strings/HomeWork Sheet Solutions/3. Convert String to LowerCase.cpp: -------------------------------------------------------------------------------- 1 | // User function Template for C++ 2 | 3 | class Solution { 4 | public: 5 | string toLower(string &S,int index=-2) { 6 | if(index==-1) return S; 7 | if(index==-2) index=S.size()-1; 8 | if(S[index]<'a') S[index]+='a'-'A'; 9 | return toLower(S,index-1); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/056. Recursion in Strings/HomeWork Sheet Solutions/4. Reverse a String.cpp: -------------------------------------------------------------------------------- 1 | // User function Template for C++ 2 | class Solution { 3 | public: 4 | string revStr(string &S,int start=0,int end=-1) { 5 | if(end==-1) end=S.size()-1; 6 | if(start>=end) return S; 7 | swap(S[start],S[end]); 8 | return revStr(S,start+1,end-1); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/056. Recursion in Strings/HomeWork Sheet Solutions/5. Number of Consonants.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int countConsonants(string s,int index) 5 | { 6 | if(index==-1) 7 | return 0; 8 | if(s[index]!='a'&&s[index]!='e'&&s[index]!='i'&&s[index]!='o'&&s[index]!='u') 9 | return 1+countConsonants(s,index-1); 10 | else 11 | return countConsonants(s,index-1); 12 | } 13 | int main() 14 | { 15 | string str="consonants"; 16 | cout< https://docs.google.com/document/d/1SAYcJjyQOHJwkJl4WMQZJH3GHmx787vWa9akhV3gth0 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/057. Recursion in Binary Search/HomeWork Sheet Solutions/1. Binary Search for Non-Increasing Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool BinarySearch(int arr[], int start, int end, int X){ 4 | if(start>end) 5 | return 0; 6 | int mid=start+(end-start)/2; 7 | if(arr[mid]==X) return 1; 8 | else if(arr[mid] 2 | using namespace std; 3 | void reverse(int arr[], int start, int end){ 4 | if(start>=end) return; 5 | swap(arr[start],arr[end]); 6 | reverse(arr,start+1,end-1); 7 | } 8 | 9 | int main(){ 10 | ios::sync_with_stdio(false); 11 | cin.tie(0); 12 | int n=6,arr[] = {10,8,7,7,4,3}; 13 | reverse(arr,0,n-1); 14 | for(int i=0;i 2 | using namespace std; 3 | 4 | void rotate(int arr[], int index){ 5 | if(index==0) return; 6 | arr[index]=arr[index-1]; 7 | rotate(arr,index-1); 8 | } 9 | 10 | int main(){ 11 | int n=6,arr[] = {10,8,7,7,4,3}; 12 | int last=arr[n-1]; 13 | rotate(arr,n-1); 14 | arr[0]=last; 15 | for(int i=0; i https://docs.google.com/document/d/1jR1DMVTqNwykIWc1zapQTBVUIodKsrFSkXD5nDldnx8 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/058. Time Complexity and Space Complexity in Recursion/HomeWork Sheet Solutions/Answers: -------------------------------------------------------------------------------- 1 | 1. T.C. = O(n) = S.C. 2 | 2. T.C. = O(exponent) = S.C. 3 | 3. T.C. = O(n*n) = S.C. 4 | 4. T.C. = O(n) = S.C. 5 | 5. T.C. = O(n) = S.C. 6 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/058. Time Complexity and Space Complexity in Recursion/HomeWork Sheet Solutions/Solution_of_Day_81_180_Time_and_Space_Complexity_in_Recursion.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/058. Time Complexity and Space Complexity in Recursion/HomeWork Sheet Solutions/Solution_of_Day_81_180_Time_and_Space_Complexity_in_Recursion.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/059. Merge Sort Algorithm/Day 82_180 Merge Sort.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/059. Merge Sort Algorithm/Day 82_180 Merge Sort.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/059. Merge Sort Algorithm/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1rlcfbRod8-KLleMrA7pOcQX0Cs6Ldd7UDlKPt-mcdOs 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/059. Merge Sort Algorithm/HomeWork Sheet Solutions/1. Merge Sort for Non-Increasing Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | void merge(int arr[], int start, int mid, int end){ 5 | vector temp(end-start+1); 6 | int left = start, right = mid + 1, index = 0; 7 | while (left<=mid && right<=end){ 8 | if(arr[left] > arr[right]) 9 | temp[index] = arr[left++]; 10 | else 11 | temp[index] = arr[right++]; 12 | index++; 13 | } 14 | while (left<=mid) temp[index++] = arr[left++]; 15 | while (right<=end) temp[index++] = arr[right++]; 16 | index = 0; 17 | while (start<=end) arr[start++] = temp[index++]; 18 | } 19 | 20 | void mergeSort(int arr[], int start, int end){ 21 | if (start==end) 22 | return; 23 | int mid = start + (end - start)/2; 24 | mergeSort(arr, start, mid); 25 | mergeSort(arr, mid+1, end); 26 | merge(arr, start, mid, end); 27 | } 28 | 29 | int main(){ 30 | int n=7,arr[] = {1,2,3,4,5,6,7}; 31 | mergeSort(arr,0,n-1); 32 | for (int i=0; i https://docs.google.com/document/d/1IB8LQ5DaK4TPp-Z_lTI4AJ1jVXLBX1pgwt8iVN9apPo 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/060. Quick Sort Algorithm/HomeWork Sheet Solutions/1. Quick Sort for Descending Order.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | int partition(int arr[], int start, int end){ 5 | int pos = start; 6 | for (int i = start; i <= end; i++) 7 | if(arr[i] >= arr[end]) 8 | swap(arr[i], arr[pos++]); 9 | return pos - 1; 10 | } 11 | void quickSort(int arr[], int start, int end){ 12 | if (start >= end) 13 | return; 14 | int pivot = partition(arr, start, end); 15 | quickSort(arr, start, pivot - 1); 16 | quickSort(arr, pivot + 1, end); 17 | } 18 | 19 | int main(){ 20 | int n=10, arr[] = {6,4,2,8,13,7,11,9,3,6}; 21 | quickSort(arr, 0, n-1); 22 | for (int i = 0; i < n; i++){ 23 | cout << arr[i] << " "; 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/060. Quick Sort Algorithm/HomeWork Sheet Solutions/Day_85_180__Quick_Sort_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/060. Quick Sort Algorithm/HomeWork Sheet Solutions/Day_85_180__Quick_Sort_.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/Day 86_180 Recursion on Subsequence.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/Day 86_180 Recursion on Subsequence.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1bBQHnmBCQ73dZ4CAwKtCwqS1HS-VyPSsEWNGMCtycTY 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/HomeWork Sheet Solutions/1. Subsets.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void subsequences(vector& arr, int index, int n, vector>& ans, vector& temp){ 4 | if(index == n){ 5 | ans.push_back(temp); 6 | return; 7 | } 8 | subsequences(arr, index+1, n, ans, temp); 9 | temp.push_back(arr[index]); 10 | subsequences(arr, index+1, n, ans, temp); 11 | temp.pop_back(); 12 | } 13 | vector> subsets(vector& nums) { 14 | vector> ans; vector temp; 15 | subsequences(nums, 0, nums.size(), ans, temp); 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/HomeWork Sheet Solutions/2. Generate Parentheses.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void Parenthesis(int n, int left, int right, vector& ans, string& temp){ 4 | if(left+right == 2*n){ 5 | ans.push_back(temp); 6 | return; 7 | } 8 | if(left < n){ 9 | temp.push_back('('); 10 | Parenthesis(n, left+1, right, ans, temp); 11 | temp.pop_back(); 12 | } 13 | if(right < left){ 14 | temp.push_back(')'); 15 | Parenthesis(n, left, right+1, ans, temp); 16 | temp.pop_back(); 17 | } 18 | } 19 | vector generateParenthesis(int n) { 20 | vector ans; 21 | string temp; 22 | Parenthesis(n, 0, 0, ans, temp); 23 | return ans; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/HomeWork Sheet Solutions/3. Sums Of Subsequences.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | void SumsOfSubsequence(int arr[], int index, int sum=0){ 6 | if(index == -1){ 7 | cout << sum << '\n'; 8 | return; 9 | } 10 | SumsOfSubsequence(arr, index-1, sum); 11 | SumsOfSubsequence(arr, index-1, sum+arr[index]); 12 | } 13 | 14 | int main(){ 15 | int n=3,arr[] = {1,2,3}; 16 | SumsOfSubsequence(arr, n-1); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/HomeWork Sheet Solutions/Day_86_180_Recursion_on_Subsequence_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/061. Recursion on Subsequence || Print All Subsequence || Generate Parentheses/HomeWork Sheet Solutions/Day_86_180_Recursion_on_Subsequence_.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/062. Recursion on Subset Sum || Target Sum/Day 87_180 Recursion on Subset.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/062. Recursion on Subset Sum || Target Sum/Day 87_180 Recursion on Subset.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/062. Recursion on Subset Sum || Target Sum/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1spu4emqSGAvfa9GCwK3g-2mDWbli7izhiGqMqMQU7KQ 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/062. Recursion on Subset Sum || Target Sum/HomeWork Sheet Solutions/1. Subset Sums.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | void Sums (vector& arr, int index, int n, int sum, vector& ans) { 5 | if (index == n) { 6 | ans.push_back(sum); 7 | return; 8 | } 9 | Sums(arr, index+1, n, sum, ans); 10 | Sums(arr, index+1, n, sum+arr[index], ans); 11 | } 12 | vector subsetSums(vector arr, int N) 13 | { 14 | vector ans; 15 | Sums(arr, 0, N, 0, ans); 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/062. Recursion on Subset Sum || Target Sum/HomeWork Sheet Solutions/2. Subset Sums & Subsets.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void print (int arr[], int index, int n, int sum, vector&temp) { 5 | if (index == n) { 6 | cout << sum << " - "; 7 | cout << "{"; 8 | for (int i = 0; i < temp.size(); i++) { 9 | cout << temp[i]; 10 | if (i != temp.size() - 1) cout << ","; 11 | } 12 | cout << "}"; 13 | cout << endl; 14 | return; 15 | } 16 | print(arr, index+1, n, sum, temp); 17 | temp.push_back(arr[index]); 18 | print(arr, index+1, n, sum+arr[index], temp); 19 | temp.pop_back(); 20 | } 21 | 22 | int main() { 23 | int n=4, arr[] = {1, 2, 3, 4}; 24 | vector temp; 25 | print(arr, 0, n, 0, temp); 26 | } 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/063. Recursion Perfect Sum Problem || Target Sum with Repetition/Day 88_180 Recursion_ Perfect Sum Problem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/063. Recursion Perfect Sum Problem || Target Sum with Repetition/Day 88_180 Recursion_ Perfect Sum Problem.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/063. Recursion Perfect Sum Problem || Target Sum with Repetition/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1Gg8eOt6PhAkvQ4R-GhYvnQCbF5Pk_Ozn4DPyxjoEkYQ 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/063. Recursion Perfect Sum Problem || Target Sum with Repetition/HomeWork Sheet Solution/1. Subset with sum divisible by m.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | bool divisible (vector& arr, int index, int n, int m, int sum) { 4 | if (sum && sum % m == 0) 5 | return 1; 6 | if (index == n) 7 | return 0; 8 | return divisible(arr, index+1, n, m, sum) || divisible(arr, index+1, n, m, sum+arr[index]); 9 | } 10 | int DivisibleByM(vectornums, int m){ 11 | return divisible(nums, 0, nums.size(), m, 0); 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/Day 89_180 Permutations of Arrays.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/Day 89_180 Permutations of Arrays.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1yEcj3HusMbQhK9PJAJrith3im9Kf8ldkcHO-JI_yiF4 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/HomeWork Sheet Solutions/1. Permutations of Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void permutations(vector& arr, vector>& ans, int index) { 4 | if (index == arr.size()) { 5 | ans.push_back(arr); return; 6 | } 7 | for (int i = index; i < arr.size(); i++) { 8 | swap(arr[index], arr[i]); 9 | permutations(arr, ans, index+1); 10 | swap(arr[index], arr[i]); 11 | } 12 | } 13 | vector> permute(vector& nums) { 14 | vector> ans; 15 | permutations(nums, ans, 0); 16 | return ans; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/HomeWork Sheet Solutions/2. Permutations of a given String.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | void permute(string& str, vector& ans, int index) { 5 | if (index == str.size()) { 6 | ans.push_back(str); 7 | return; 8 | } 9 | vector visited(256, 0); 10 | for (int i = index; i < str.size(); i++) { 11 | if (!visited[str[i]]) { 12 | swap(str[index], str[i]); 13 | permute(str, ans, index+1); 14 | swap(str[index], str[i]); 15 | visited[str[i]] = 1; 16 | } 17 | } 18 | } 19 | vectorfind_permutation(string S) 20 | { 21 | vector ans; 22 | permute(S, ans, 0); 23 | return ans; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/HomeWork Sheet Solutions/3. Permutations II.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void permute(vector& arr, vector>& ans, int index) { 4 | if (index == arr.size()) { 5 | ans.push_back(arr); 6 | return; 7 | } 8 | vector visited(21, 0); 9 | for (int i = index; i < arr.size(); i++) { 10 | if (!visited[arr[i]+10]) { 11 | swap(arr[index], arr[i]); 12 | permute(arr, ans, index+1); 13 | swap(arr[index], arr[i]); 14 | visited[arr[i]+10] = 1; 15 | } 16 | } 17 | } 18 | vector> permuteUnique(vector& nums) { 19 | vector> ans; 20 | permute(nums, ans, 0); 21 | return ans; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/HomeWork Sheet Solutions/Day_89_180_Permutations_of_Arrays_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/064. Permutation of Arrays and Strings/HomeWork Sheet Solutions/Day_89_180_Permutations_of_Arrays_.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/065. Permutation with repetition || Ways to Sum N/Day 92_180 Recursion permutation 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/065. Permutation with repetition || Ways to Sum N/Day 92_180 Recursion permutation 2.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/065. Permutation with repetition || Ways to Sum N/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1XIlmd87WT9s18dzkwoIbdDO3PuvZFMCml_A-wF8I9UA 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/068. Recursion Rat in a Maze Problem/Rat in a Maze.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | int row[4] = {1,-1,0,0}; 4 | int col[4] = {0,0,-1,1}; 5 | string dir = "DULR"; 6 | 7 | bool valid(int i, int j, int n) { 8 | return i>=0 && j>=0 && i>& matrix, int i, int j, int n, string& path, vector& ans, vector>& visited) { 12 | if (i == n-1 && j == n-1) { 13 | ans.push_back(path); 14 | return; 15 | } 16 | visited[i][j] = 1; 17 | for (int k = 0; k < 4; k++) { 18 | if (valid(i+row[k], j+col[k], n) && matrix[i+row[k]][j+col[k]] && !visited[i+row[k]][j+col[k]]) { 19 | path.push_back(dir[k]); 20 | Total(matrix, i+row[k], j+col[k], n, path, ans, visited); 21 | path.pop_back(); 22 | } 23 | } 24 | visited[i][j] = 0; 25 | } 26 | 27 | vector findPath(vector> &m, int n) { 28 | vector> visited(n, vector(n, 0)); 29 | vector ans; 30 | string path; 31 | if (m[0][0] == 0 || m[n-1][n-1] == 0) 32 | return ans; 33 | Total(m, 0, 0, n, path, ans, visited); 34 | return ans; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/069. Print N-bit binary numbers having more 1s than 0s/Print N-bit binary numbers having more 1s than 0s.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | void binary(int one, int zero, int index, int n, vector& ans, string temp) { 4 | if (index == n) { 5 | ans.push_back(temp); 6 | return; 7 | } 8 | 9 | temp.push_back('1'); 10 | binary(one+1, zero, index+1, n, ans, temp); 11 | temp.pop_back(); 12 | 13 | if (one > zero) { 14 | temp.push_back('0'); 15 | binary(one, zero+1, index+1, n, ans, temp); 16 | temp.pop_back(); 17 | } 18 | } 19 | vector NBitBinary(int N) 20 | { 21 | vector ans; 22 | string temp = "1"; 23 | binary(1,0,1,N,ans,temp); 24 | return ans; 25 | } 26 | }; 27 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/070. Introduction To Object Oriented Programming/Day 99_180 Object Oriented Programming.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/070. Introduction To Object Oriented Programming/Day 99_180 Object Oriented Programming.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/070. Introduction To Object Oriented Programming/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1Wi3Vb5HO7NemmoVqCR_VxCbBmRJkAAETuwisWqI3rUc 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/071. Constructor and Destructor in C++/Day 100_180 Constructor and Destructor.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/071. Constructor and Destructor in C++/Day 100_180 Constructor and Destructor.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/071. Constructor and Destructor in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1AvF6VNPoTAIjmvmGY6WiG_WA64PlMhX1-H_tfwBSaMM 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/072. Object Oriented Programming: Static data Member and Function | Encapsulation | Abstraction in C++/Day 101_180 Static data member.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/072. Object Oriented Programming: Static data Member and Function | Encapsulation | Abstraction in C++/Day 101_180 Static data member.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/072. Object Oriented Programming: Static data Member and Function | Encapsulation | Abstraction in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1yZgg5Jfky0cFY8UcbnQOaYg02msXyCaVuTIXXzH6Ya0 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/074. Type of Inheritance in C++ | Single Inheritance | Multiple | Hybrid | Multipath | Multilevel/Day 106_180 Type of Inheritance.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/074. Type of Inheritance in C++ | Single Inheritance | Multiple | Hybrid | Multipath | Multilevel/Day 106_180 Type of Inheritance.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/074. Type of Inheritance in C++ | Single Inheritance | Multiple | Hybrid | Multipath | Multilevel/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1liT4V5S4rxanlkzqX4tsRslkh9d_NSpN9-01962nJ5s 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/075. Polymorphism and Virtual Function in C++/Day 107_180 Polymorphism.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/075. Polymorphism and Virtual Function in C++/Day 107_180 Polymorphism.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/075. Polymorphism and Virtual Function in C++/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1w95UtbHuoBNTrs5ptSCIsdveDUEoJAyoPPBTXWIOLSo 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/080. Reverse a Linked List | Middle of Linked List | Rotate Linked List/HomeWork Solution/Rotate List.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | class Solution { 12 | public: 13 | ListNode* rotateRight(ListNode* head, int k) { 14 | if (head) { 15 | int size = 0; 16 | ListNode *curr = head, *tail = head, *prev = NULL; 17 | while (curr) { 18 | tail = curr; 19 | curr = curr->next; 20 | size++; 21 | } 22 | if (k %= size) { 23 | int moves = size - k; 24 | curr = head; 25 | while (moves--) { 26 | prev = curr; 27 | curr = curr->next; 28 | } 29 | prev->next = NULL; 30 | tail->next = head; 31 | head = curr; 32 | } 33 | } 34 | return head; 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/Day 119_180 Doubly Linked List.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/Day 119_180 Doubly Linked List.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1CQGiuzxtvrk3fe1l0u8VhfJndA_HZACdTFd-iXdwML0 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/HomeWork Sheet Solutions/2. Doubly linked list Insertion at given position.cpp: -------------------------------------------------------------------------------- 1 | /* a Node of the doubly linked list 2 | struct Node 3 | { 4 | int data; 5 | struct Node *next; 6 | struct Node *prev; 7 | Node(int x) { data = x; next = prev = NULL; } 8 | }; */ 9 | 10 | //Function to insert a new node at given position in doubly linked list. 11 | void addNode(Node *head, int pos, int data) 12 | { 13 | Node *curr = head; 14 | while(pos--) { 15 | curr = curr->next; 16 | } 17 | Node *temp = new Node(data); 18 | temp->next = curr->next; 19 | temp->prev = curr; 20 | curr->next = temp; 21 | if (temp->next) temp->next->prev = temp; 22 | } 23 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/HomeWork Sheet Solutions/3. Reverse a Doubly Linked List.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | struct Node 3 | { 4 | int data; 5 | Node * next; 6 | Node * prev; 7 | Node (int x) 8 | { 9 | data=x; 10 | next=NULL; 11 | prev=NULL; 12 | } 13 | 14 | }; 15 | */ 16 | class Solution 17 | { 18 | public: 19 | Node* reverseDLL(Node * head) 20 | { 21 | while (head) { 22 | swap(head->prev, head->next); 23 | if (head->prev == NULL) return head; 24 | head = head->prev; 25 | } 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/HomeWork Sheet Solutions/Day_119_180_Doubly_Linked_List.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/082. Introduction to Doubly Linked List || Insertion and Deletion in Doubly Linked List/HomeWork Sheet Solutions/Day_119_180_Doubly_Linked_List.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/083. LinkedList Problems: Remove Duplicates | Merge 2 Sorted LinkedList | Sort a LinkedList of 0 1 and 2/Day 120_180 LinkedList Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/083. LinkedList Problems: Remove Duplicates | Merge 2 Sorted LinkedList | Sort a LinkedList of 0 1 and 2/Day 120_180 LinkedList Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/083. LinkedList Problems: Remove Duplicates | Merge 2 Sorted LinkedList | Sort a LinkedList of 0 1 and 2/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1ROjylPATMkp-0jDy3wv9QIZgsth5cGVdmmmxJJTVmQE 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/084. Circular Linked List: Detect Loop in Linked List || Find Length of Loop/Day 121_180 Circular LinkedList Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/084. Circular Linked List: Detect Loop in Linked List || Find Length of Loop/Day 121_180 Circular LinkedList Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/084. Circular Linked List: Detect Loop in Linked List || Find Length of Loop/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1FsobT5kA17nz-9aObSoOBQA3Fh9niRQtS-DRQx5m4YU 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size/Day 123_180 LinkedList Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size/Day 123_180 LinkedList Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1zdmhxDllhHhUjSQ_CtmvCz7XO5-XEKsLKdaYAFEAi_M 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size/HomeWork Sheet Solutions/1. Reverse a sublist of a linked list.cpp: -------------------------------------------------------------------------------- 1 | //User function Template for C++ 2 | 3 | /*Link list node 4 | struct Node { 5 | int data; 6 | struct Node *next; 7 | Node(int x) { 8 | data = x; 9 | next = NULL; 10 | } 11 | };*/ 12 | 13 | class Solution 14 | { 15 | public: 16 | Node* reverseBetween(Node* head, int m, int n) 17 | { 18 | Node* temp = new Node(0); 19 | temp->next = head; 20 | head = temp; 21 | Node *curr = head, *prev = NULL; 22 | n -= m; 23 | n++; 24 | while (m--) { 25 | prev = curr; 26 | curr = curr->next; 27 | } 28 | Node *first = prev; 29 | Node *second = curr; 30 | while (n--) { 31 | Node *front = curr->next; 32 | curr->next = prev; 33 | prev = curr; 34 | curr = front; 35 | } 36 | first->next = prev; 37 | second->next = curr; 38 | return head->next; 39 | } 40 | }; 41 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size/HomeWork Sheet Solutions/Day_123_180_LinkedList_Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/086. Add two numbers represented by linked lists | Reverse a Linked List in groups of given size/HomeWork Sheet Solutions/Day_123_180_LinkedList_Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/087. Hard Problem on Linked List: Flattening a Linked List | Merge K Sorted Linked List/Day 126_180 LinkedList Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/087. Hard Problem on Linked List: Flattening a Linked List | Merge K Sorted Linked List/Day 126_180 LinkedList Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/087. Hard Problem on Linked List: Flattening a Linked List | Merge K Sorted Linked List/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1GRP-gvrn5duxv8v8PTn-j8aqJ-xFjEUcwSXS7ldObdY 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/088. LinkedList Series End Here: Clone a linked list with next and random pointer/Day 127_180 LinkedList Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/088. LinkedList Series End Here: Clone a linked list with next and random pointer/Day 127_180 LinkedList Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/088. LinkedList Series End Here: Clone a linked list with next and random pointer/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1M_yw69asYny1J20Ms3Jf4A_j1ikp4vZp9-JMY4tsd_o 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/Day 133_180 Introduction to Stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/Day 133_180 Introduction to Stack.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1zOezQPKnxDO_TILFLsJQ8A49Ovv6MqkQi3MHCzidae0 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/HomeWork Sheet Solutions/1. Implement stack using array.cpp: -------------------------------------------------------------------------------- 1 | //Function to push an integer into the stack. 2 | /* 3 | class MyStack 4 | { 5 | private: 6 | int arr[1000]; 7 | int top; 8 | public: 9 | MyStack(){top=-1;} 10 | int pop(); 11 | void push(int); 12 | }; 13 | */ 14 | 15 | void MyStack :: push(int x) 16 | { 17 | if (top == 999) { 18 | return; 19 | } 20 | top++; 21 | arr[top] = x; 22 | } 23 | 24 | //Function to remove an item from top of the stack. 25 | int MyStack :: pop() 26 | { 27 | if (top == -1) { 28 | return -1; 29 | } 30 | return arr[top--]; 31 | } 32 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/HomeWork Sheet Solutions/2. Implement Stack using Linked List.cpp: -------------------------------------------------------------------------------- 1 | //Function to push an integer into the stack. 2 | void MyStack ::push(int x) 3 | { 4 | StackNode *temp = new StackNode(x); 5 | temp->next = top; 6 | top = temp; 7 | } 8 | 9 | //Function to remove an item from top of the stack. 10 | int MyStack ::pop() 11 | { 12 | if (top == NULL) { 13 | return -1; 14 | } 15 | StackNode *temp = top; 16 | top = top->next; 17 | int x = temp->data; 18 | delete temp; 19 | return x; 20 | } 21 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/HomeWork Sheet Solutions/3. Stack Operations.cpp: -------------------------------------------------------------------------------- 1 | class Geeks { 2 | public: 3 | // Function to insert element to stack 4 | void insert(stack& st, int x) { 5 | st.push(x); 6 | } 7 | 8 | // Function to pop element from stack 9 | void remove(stack& st) { 10 | st.pop(); 11 | } 12 | 13 | void headOf_Stack(stack& st) { 14 | cout << st.top() << '\n'; 15 | } 16 | 17 | // Function to find the element in stack, print Yes,if found, else print No. 18 | void find(stack st, int val) { 19 | while (st.size()) { 20 | if (st.top() == val) { 21 | cout << "Yes" << '\n'; 22 | return; 23 | } 24 | st.pop(); 25 | } 26 | cout << "No" << '\n'; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/HomeWork Sheet Solutions/Soltuion_of_Day_133_180_Introduction_to_Stack.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/089. Introduction To STACK || Implement Stack Using Arrays and LinkedList/HomeWork Sheet Solutions/Soltuion_of_Day_133_180_Introduction_to_Stack.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/Day 134_180 Stack Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/Day 134_180 Stack Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1uUFD8EnayasxkYJZkg50um7hFz4dXenSBZRWtO_zqTY 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/HomeWork Sheet Solutions/1. Backspace String Compare.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void backspace (string& s) { 4 | stack st; 5 | for (int i = 0; i < s.size(); i++) { 6 | if (s[i] != '#') { 7 | st.push(s[i]); 8 | } 9 | else if (!st.empty()) { 10 | st.pop(); 11 | } 12 | } 13 | s = ""; 14 | while (!st.empty()) { 15 | s.push_back(st.top()); 16 | st.pop(); 17 | } 18 | } 19 | 20 | bool backspaceCompare(string s, string t) { 21 | backspace(s); 22 | backspace(t); 23 | if (s == t) { 24 | return true; 25 | } 26 | else { 27 | return false; 28 | } 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/090. STACK : Valid Parentheses | Print Bracket Number | Reverse Array | Get min at pop/HomeWork Sheet Solutions/4. Minimum Add to Make Parentheses Valid.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minAddToMakeValid(string s) { 4 | int cnt = 0, ans = 0; 5 | for (int i = 0; i < s.size(); i++) { 6 | if (s[i] == '(') { 7 | cnt++; 8 | } 9 | else { 10 | if (!cnt) 11 | ans++; 12 | else 13 | cnt--; 14 | } 15 | } 16 | return ans + cnt; 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem/Day 135_180 Stack More Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem/Day 135_180 Stack More Problems.pdf -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem/HomeWork Sheet Link: -------------------------------------------------------------------------------- 1 | HomeWork Sheet -> https://docs.google.com/document/d/1RXoxLBeSigZyX4Q8sEz0_61AvotQdmtRbzbjceAoPvM 2 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem/HomeWork Sheet Solutions/4. Next Greater.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector nextGreaterElement(vector& nums1, vector& nums2) { 4 | vector temp(nums2.size(), -1); 5 | stack st; 6 | unordered_map m; 7 | for (int i = 0; i < nums2.size(); i++) { 8 | m[nums2[i]] = i; 9 | while (!st.empty() && nums2[i] > nums2[st.top()]) { 10 | temp[st.top()] = nums2[i]; 11 | st.pop(); 12 | } 13 | st.push(i); 14 | } 15 | vector ans(nums1.size(), -1); 16 | for (int i = 0; i < nums1.size(); i++) { 17 | ans[i] = temp[m[nums1[i]]]; 18 | } 19 | return ans; 20 | } 21 | }; 22 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/HomeWork Sheets/091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem/HomeWork Sheet Solutions/Solution_of_Day_135_180_Stack_More_Problems.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hsd1807/Coder-Army/14c936793f38cd2bf634fe8e48f00ffbf58d0c71/Data Structures and Algorithms/HomeWork Sheets/091. Stack Problem: Next Greater Element | Next Smaller Element | Stock Span Problem/HomeWork Sheet Solutions/Solution_of_Day_135_180_Stack_More_Problems.pdf --------------------------------------------------------------------------------