├── src ├── DS │ ├── readme.md │ ├── Class2_BitManipulation_Assignments │ │ ├── MajorityElement.java │ │ └── SingleNumberTwo.java │ ├── Class4_Sorting │ │ ├── MergeSort.java │ │ ├── RadixSort.java │ │ ├── CountringSort.java │ │ ├── SelectionSort.java │ │ ├── BubbleSort.java │ │ ├── QuickSort.java │ │ └── InsertionSort.java │ ├── Class5_Arrays │ │ ├── BinarySearch │ │ │ ├── SquareRoot.java │ │ │ └── FirstBadVersion.java │ │ └── readme.md │ ├── Class3_Math_Assignments │ │ ├── Pow_x_n.java │ │ └── CountingPrime.java │ └── Class4_Sorting_Assignments │ │ └── Sort_Colors.java ├── Implementation │ ├── LinkedList │ │ ├── DoublyLinkedList.java │ │ └── ListNode.java │ ├── Driver.java │ ├── Stack │ │ └── Stack.java │ └── Queue │ │ └── Queue.java ├── Leetcode │ ├── Practice │ │ ├── LinkedList │ │ │ ├── SinglyListNode.java │ │ │ ├── TwoPointer │ │ │ │ ├── Cycle.java │ │ │ │ ├── Cycle2.java │ │ │ │ └── IntersectionOfTwoList.java │ │ │ ├── MergeTwoSortedList.java │ │ │ ├── RemoveNthNode.java │ │ │ ├── RotateList.java │ │ │ └── LinkedList.java │ │ ├── Array │ │ │ ├── TwoSum.js │ │ │ ├── TwoSum2.js │ │ │ ├── MissingNumber.java │ │ │ ├── DuplicateNumber287.java │ │ │ ├── Conclusion │ │ │ │ ├── HeightChecker.java │ │ │ │ ├── ThirdMaximum.java │ │ │ │ └── FindAllNumbersDisappeared.java │ │ │ ├── ContainsDuplicate.java │ │ │ ├── CheckForDouble.java │ │ │ ├── DuplicateZeros.java │ │ │ ├── InPlace │ │ │ │ ├── MoveZeroes.java │ │ │ │ ├── ReplaceElementswithGreatestElement.java │ │ │ │ └── SortArrayByParity.java │ │ │ ├── RotateArray.java │ │ │ ├── MergeSortedArray.java │ │ │ ├── RemoveElement.java │ │ │ ├── ValidMountain.java │ │ │ ├── RemoveDuplicate.java │ │ │ └── TwoSum.java │ │ ├── BitManipulation │ │ │ ├── NumberOf1Bits.java │ │ │ ├── ReverseBits.java │ │ │ └── HammingDistance.java │ │ ├── String │ │ │ ├── ReverseString.java │ │ │ ├── ReverseInteger.js │ │ │ ├── ReverseInteger.java │ │ │ └── ReverseString2.java │ │ ├── BinarySearch │ │ │ ├── BinarySearch.java │ │ │ ├── SearchInsertPosition.java │ │ │ └── FirstAndLast.java │ │ └── TwoPointer │ │ │ └── SquareSortedArray.java │ └── Tutorial │ │ └── Array │ │ ├── MaxConsecutiveOnes.java │ │ └── EvenNumberofDigits.java └── Educative │ └── DSInJava │ └── Array │ ├── ArrayOfProducts.java │ ├── SumOfN.java │ └── MergeTwoSortedArrays.java ├── .idea ├── .gitignore ├── vcs.xml ├── modules.xml ├── misc.xml ├── runConfigurations.xml └── uiDesigner.xml ├── .gitignore ├── DS-ALGO.iml └── readme.md /src/DS/readme.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/DS/Class2_BitManipulation_Assignments/MajorityElement.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/MergeSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | public class MergeSort { 4 | } 5 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/RadixSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | public class RadixSort { 4 | } 5 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/CountringSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | public class CountringSort { 4 | } 5 | -------------------------------------------------------------------------------- /src/Implementation/LinkedList/DoublyLinkedList.java: -------------------------------------------------------------------------------- 1 | package Implementation.LinkedList; 2 | 3 | public class DoublyLinkedList { 4 | } 5 | -------------------------------------------------------------------------------- /src/Implementation/Driver.java: -------------------------------------------------------------------------------- 1 | package Implementation; 2 | 3 | import Implementation.Stack.Stack; 4 | 5 | public class Driver { 6 | public Stack stack = new Stack(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/SinglyListNode.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList; 2 | 3 | public class SinglyListNode { 4 | int val; 5 | SinglyListNode next; 6 | SinglyListNode(int x) { val = x; } 7 | } 8 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/TwoSum.js: -------------------------------------------------------------------------------- 1 | function twoSum(nums: number[], target: number): number[] { 2 | const myMap: Map = new Map(); 3 | 4 | for (let i = 0; i < nums.length; i++) { 5 | if (myMap.get(target-nums[i]) ?? 0) { 6 | return [i, myMap.get(target-nums[i]) ?? 0]; 7 | } else { 8 | myMap.set(nums[i], i); 9 | } 10 | } 11 | return []; 12 | }; -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/TwoSum2.js: -------------------------------------------------------------------------------- 1 | function twoSum(nums: number[], target: number): number[] { 2 | const myMap: Map = new Map(); 3 | 4 | for (let i = 0; i < nums.length; i++) { 5 | if (myMap.get(target-nums[i]) ?? 0) { 6 | return [myMap.get(target-nums[i]) ?? 0, i+1]; 7 | } else { 8 | myMap.set(nums[i], i+1); 9 | } 10 | } 11 | return []; 12 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | #output folder 26 | ./out -------------------------------------------------------------------------------- /src/DS/Class2_BitManipulation_Assignments/SingleNumberTwo.java: -------------------------------------------------------------------------------- 1 | package DS.Class2_BitManipulation_Assignments; 2 | 3 | public class SingleNumberTwo { 4 | 5 | public static int singleNumber(int[] nums) { 6 | 7 | return 1; 8 | } 9 | 10 | public static void main(String[] args) { 11 | 12 | int[] arr = {3,3,3,5}; 13 | 14 | System.out.println(SingleNumberTwo.singleNumber(new int[]{0, 1, 0, 1, 0, 1, 99})); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /DS-ALGO.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/BitManipulation/NumberOf1Bits.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.BitManipulation; 2 | 3 | public class NumberOf1Bits { 4 | // Works with C++ but doesn't work with JAVA 5 | public int hammingWeight(int n) { 6 | int count = 0; 7 | while(n > 0) { 8 | count++; 9 | n = n & n-1; 10 | } 11 | return count; 12 | } 13 | 14 | 15 | public static void main(String[] args) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/String/ReverseString.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.String; 2 | 3 | public class ReverseString { 4 | public void reverseString(char[] s) { 5 | int lo = 0, hi = s.length-1; 6 | while(lo < hi) { 7 | char temp = s[lo]; 8 | s[lo] = s[hi]; 9 | s[hi] = temp; 10 | lo++; 11 | hi--; 12 | } 13 | } 14 | 15 | public static void main(String[] args) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Implementation/LinkedList/ListNode.java: -------------------------------------------------------------------------------- 1 | package Implementation.LinkedList; 2 | 3 | 4 | public class ListNode { 5 | public int val; 6 | public ListNode next; 7 | public ListNode() {} 8 | public ListNode(int val) { this.val = val; } 9 | public ListNode(int val, ListNode next) { this.val = val; this.next = next; } 10 | 11 | @Override 12 | public String toString() { 13 | return "ListNode{" + 14 | "data=" + val + 15 | '}'; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/MissingNumber.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | public class MissingNumber { 4 | static int missingNumber(int[] nums) { 5 | int sum = (int) (nums.length* ((float) (nums.length + 1)/2)); 6 | for (int i = 0; i < nums.length; i++) { 7 | sum -= nums[i]; 8 | } 9 | return sum; 10 | } 11 | 12 | public static void main(String[] args) { 13 | int[] nums = {}; 14 | System.out.println(missingNumber(nums)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/String/ReverseInteger.js: -------------------------------------------------------------------------------- 1 | // DID Reverse Integer with the help of JS, AS String support in JS is much better 2 | 3 | // Also learnt new thing about comparing values based on HEXCODE for 2^31 and -2^31 4 | function reverse(x: number): number { 5 | let reversed = parseInt(x.toString().split('').reverse().join('')) * Math.sign(x); 6 | 7 | // Comparing for overflow situation value greater than 2^31 and value less than -2^31 8 | return (reversed <= 0x7fffffff && reversed >= -0x80000000) ? reversed : 0; 9 | 10 | }; -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/DuplicateNumber287.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | public class DuplicateNumber287 { 4 | static int duplicateNumber(int[] nums) { 5 | int sum = (int) ((nums.length-1)* ((float) (nums.length)/2)); 6 | for (int i = 0; i < nums.length; i++) { 7 | sum -= nums[i]; 8 | } 9 | return Math.abs(sum); 10 | } 11 | 12 | public static void main(String[] args) { 13 | int[] nums = {1,3,4,2,2}; 14 | System.out.println(duplicateNumber(nums)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/Conclusion/HeightChecker.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array.Conclusion; 2 | 3 | import java.util.Arrays; 4 | 5 | public class HeightChecker { 6 | public static int heightChecker(int[] nums) { 7 | int[] result = nums.clone(); 8 | Arrays.sort(result); 9 | 10 | int count = 0; 11 | for (int i = 0; i < nums.length; i++) { 12 | if(nums[i] != result[i]) count++; 13 | } 14 | return count; 15 | } 16 | 17 | public static void main(String[] args) { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/BitManipulation/ReverseBits.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.BitManipulation; 2 | 3 | public class ReverseBits { 4 | /* 5 | C++ Solution, I've done it with C++ because string reversal in C++ is not pain in the ass such as JAVA 6 | uint32_t reverseBits(uint32_t n) { 7 | string s = bitset<32>(n).to_string(); 8 | reverse(s.begin(), s.end()); 9 | return (int)bitset<32>(s).to_ulong(); 10 | } 11 | */ 12 | 13 | 14 | 15 | public static void main(String[] args) { 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/Conclusion/ThirdMaximum.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array.Conclusion; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ThirdMaximum { 6 | public static int thirdMax(int[] nums) { 7 | Arrays.sort(nums); 8 | int count = 1; 9 | for (int i = 1; i < nums.length; i++) { 10 | if(nums[i] != nums[i-1]) count++; 11 | if(count == 3) return nums[0]; 12 | 13 | } 14 | return nums[nums.length-1]; 15 | } 16 | 17 | public static void main(String[] args) { 18 | System.out.println(thirdMax(new int[]{2,2,2,2, 2, 1})); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/BinarySearch/BinarySearch.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.BinarySearch; 2 | 3 | public class BinarySearch { 4 | public static int binarySearch(int[] arr, int target) { 5 | int low = 0; int high = arr.length; 6 | while(low < high) { 7 | int mid = low + (high - low) / 2; 8 | if (arr[mid] == target) return mid; 9 | else if (arr[mid] > target) high = mid; 10 | else low = mid+1; 11 | } 12 | return -1; 13 | }; 14 | 15 | public static void main(String[] args) { 16 | System.out.println(binarySearch(new int[]{-1,0,3,5,9,12}, 9)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/TwoPointer/Cycle.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList.TwoPointer; 2 | 3 | import Implementation.LinkedList.ListNode; 4 | 5 | public class Cycle { 6 | public boolean hasCycle(ListNode head) { 7 | ListNode slow = head; 8 | ListNode fast = head; 9 | 10 | while(fast != null) { 11 | // In case fast.next is null may lead to null pointer exception in next line 12 | if (fast.next == null) return false; 13 | fast = fast.next.next; 14 | slow = slow.next; 15 | if(fast == slow) return true; 16 | } 17 | return false; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Implementation/Stack/Stack.java: -------------------------------------------------------------------------------- 1 | package Implementation.Stack; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Stack { 6 | ArrayList arr = new ArrayList<>(); 7 | int top = -1; 8 | 9 | void push (E x) { 10 | top += 1; 11 | arr.add(top, x); 12 | }; 13 | 14 | void pop() { 15 | if(!isEmpty()) { 16 | top -= 1; 17 | } else { 18 | throw new ArrayIndexOutOfBoundsException(); 19 | } 20 | }; 21 | 22 | boolean isEmpty() { 23 | return top == -1; 24 | }; 25 | 26 | int size() { 27 | return top+1; 28 | } 29 | 30 | E peek() { 31 | return arr.get(top); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Leetcode/Tutorial/Array/MaxConsecutiveOnes.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Tutorial.Array; 2 | 3 | public class MaxConsecutiveOnes { 4 | static int maxConsecutiveOnes(int[] nums) { 5 | int count = 0, maxCount = 0; 6 | for (int i = 0; i < nums.length; i++) { 7 | if(nums[i] == 1) { 8 | count++; 9 | if(count > maxCount) { 10 | maxCount = count; 11 | } 12 | } else { 13 | count = 0; 14 | } 15 | } 16 | return maxCount; 17 | } 18 | 19 | public static void main(String[] args) { 20 | int[] nums = {0}; 21 | System.out.println(maxConsecutiveOnes(nums)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Leetcode/Tutorial/Array/EvenNumberofDigits.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Tutorial.Array; 2 | 3 | public class EvenNumberofDigits { 4 | static int evenNumberOfDigits(int[] nums) { 5 | int count = 0; 6 | boolean isEven; 7 | for (int i = 0; i < nums.length; i++) { 8 | isEven = false; 9 | if (nums[i] > 9) { 10 | while(nums[i] > 9) { 11 | nums[i] /= 10; 12 | isEven = !isEven; 13 | } 14 | } 15 | if(isEven) count++; 16 | } 17 | return count; 18 | } 19 | 20 | public static void main(String[] args) { 21 | int[] nums = {555,901,482,1771}; 22 | System.out.println(evenNumberOfDigits(nums)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/SelectionSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class SelectionSort { 8 | static List selectionSort(List arr) { 9 | int n = arr.size(); 10 | for (int i = 0; i < n; i++) { 11 | int min = i; 12 | for (int j = 0; j < n; j++) { 13 | if (arr.get(j) < arr.get(min)) 14 | min = j; 15 | } 16 | if (i != min) 17 | Collections.swap(arr, i, min); 18 | } 19 | return arr; 20 | } 21 | 22 | public static void main(String[] args) { 23 | System.out.println(selectionSort(Arrays.asList(0,5,3,4,2,1))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/DS/Class5_Arrays/BinarySearch/SquareRoot.java: -------------------------------------------------------------------------------- 1 | package DS.Class5_Arrays.BinarySearch; 2 | 3 | public class SquareRoot { 4 | static boolean isSquareRoot(int n, int square) { 5 | if( n > square/n ) return true; 6 | return false; 7 | } 8 | 9 | static int squareRoot(int square) { 10 | if (square == 1) return 1; 11 | 12 | int left = 1, right = square; 13 | while (left < right) { 14 | int mid = left + (right - left) / 2; 15 | System.out.println(mid); 16 | if (isSquareRoot(mid, square)) right = mid; 17 | else left = mid+1; 18 | } 19 | return left-1; 20 | } 21 | 22 | public static void main(String[] args) { 23 | System.out.println(squareRoot(2147395599)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Educative/DSInJava/Array/ArrayOfProducts.java: -------------------------------------------------------------------------------- 1 | package Educative.DSInJava.Array; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ArrayOfProducts { 6 | static int[] findProduct(int[] arr) { 7 | int[] result = new int[arr.length]; 8 | for (int i = 0; i < arr.length; i++) { 9 | result[i] = 1; 10 | } 11 | 12 | for (int i = 0; i < arr.length; i++) { 13 | for (int j = 0; j < arr.length; j++) { 14 | if (j != i) { 15 | result[i] *= arr[j]; 16 | } 17 | } 18 | } 19 | return result; 20 | } 21 | 22 | public static void main(String[] args) { 23 | int[] arr = {1,2,3,4}; 24 | System.out.println(Arrays.toString(findProduct(arr))); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/ContainsDuplicate.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ContainsDuplicate { 6 | // Solution 1 with Sorting Approach 7 | static boolean containsDuplicate(int[] nums) { 8 | Arrays.sort(nums); 9 | boolean result = false; 10 | for (int i = 0; i < nums.length-1; i++) { 11 | if(nums[i] == nums[i+1]) { 12 | result = true; 13 | break; 14 | } 15 | } 16 | return result; 17 | } 18 | 19 | static boolean containsDuplicate2(int[] nums) { 20 | int count = 0; 21 | 22 | return true; 23 | } 24 | 25 | public static void main(String[] args) { 26 | int[] nums = {1,1,1,3,3,4,3,2,4,2, 3, 1}; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Educative/DSInJava/Array/SumOfN.java: -------------------------------------------------------------------------------- 1 | package Educative.DSInJava.Array; 2 | 3 | import java.util.Arrays; 4 | 5 | // Challenge 3: https://www.educative.io/module/lesson/data-structures-in-java/39Av4wzO67M 6 | public class SumOfN { 7 | static int[] findSum(int[] arr, int n) { 8 | int i = 0, j = arr.length-1; 9 | Arrays.sort(arr); 10 | 11 | while (i < j) { 12 | if ((arr[i] + arr[j]) > n) j--; 13 | else if ((arr[i] + arr[j]) < n) i++; 14 | else return new int[]{arr[i], arr[j]}; 15 | } 16 | return arr; 17 | } 18 | 19 | public static void main(String[] args) { 20 | int[] arr = {1, 21, 3, 14, 5, 60, 7, 6}; 21 | int value = 27; 22 | System.out.println(Arrays.toString(findSum(arr, value))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/DS/Class3_Math_Assignments/Pow_x_n.java: -------------------------------------------------------------------------------- 1 | package DS.Class3_Math_Assignments; 2 | 3 | public class Pow_x_n { 4 | static double myPow(double x, int n) { 5 | int res = 0; 6 | if (n%2 != 0) res = 1; 7 | if (n == 1) return x; 8 | if (n == -1) return 1/x; 9 | 10 | if(n == 2) return x*x; 11 | if (n == -2) return 1/(x*x); 12 | if(n > 0) { 13 | return res == 1 ? 14 | myPow(x, n/2) * myPow(x, n/2) * myPow(x, 1) : 15 | myPow(x, n/2) * myPow(x, n/2); 16 | } return res == 1 ? 17 | myPow(x, n/2) * myPow(x, n/2) * myPow(x, -1) : 18 | myPow(x, n/2) * myPow(x, n/2); 19 | } 20 | public static void main(String[] args) { 21 | System.out.println(myPow(2.1, 100)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/BinarySearch/SearchInsertPosition.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.BinarySearch; 2 | 3 | // Reference https://leetcode.com/problems/search-insert-position/ 4 | 5 | public class SearchInsertPosition { 6 | public static int searchInsert(int[] nums, int target) { 7 | int low = 0, hi = nums.length-1; 8 | while (low <= hi) { 9 | int mid = low + hi-low/2; 10 | // Point to remember we always compare for value greater than target 11 | if (nums[mid] >= target) { 12 | hi = mid-1; 13 | } else { 14 | low = mid+1; 15 | } 16 | } 17 | return low; 18 | } 19 | public static void main(String[] args) { 20 | System.out.println(searchInsert(new int[]{1, 3, 5, 6}, 5)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/CheckForDouble.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | public class CheckForDouble { 8 | static boolean checkIfExist(int[] nums) { 9 | Set set = new HashSet(); 10 | boolean result = false; 11 | 12 | for (int num: nums) 13 | if(set.contains((double) num/2) || set.contains((double) num*2)) { 14 | System.out.println(num); 15 | result = true; 16 | break; 17 | } else { 18 | set.add((double) num); 19 | } 20 | return result; 21 | } 22 | 23 | public static void main(String[] args) { 24 | System.out.println(checkIfExist(new int[]{14,1,7})); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/DuplicateZeros.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | import java.util.Arrays; 4 | // Reference : https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3245/ 5 | public class DuplicateZeros { 6 | public static void duplicateZeros(int[] arr) { 7 | int[] nums = arr.clone(); 8 | for (int i = 0, j = 0; i < nums.length && j < arr.length; i++, j++) { 9 | arr[j] = nums[i]; 10 | if(nums[i] == 0 && j+1 < arr.length) { 11 | j++; 12 | arr[j] = nums[i]; 13 | } 14 | } 15 | } 16 | 17 | public static void main(String[] args) { 18 | int[] arr = new int[]{0,0,0,0,0,0,0}; 19 | duplicateZeros(arr); 20 | System.out.println(Arrays.toString(arr)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/InPlace/MoveZeroes.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array.InPlace; 2 | 3 | public class MoveZeroes { 4 | public static void swap(int[] nums, int i, int j) { 5 | int temp = nums[i]; 6 | nums[i] = nums[j]; 7 | nums[j] = temp; 8 | } 9 | 10 | public static void moveZeroes(int[] nums) { 11 | int slow = 0, fast = 0; 12 | while (fast < nums.length) { 13 | if (nums[fast] != 0 && nums[slow] != 0) { 14 | fast++; 15 | slow++; 16 | } else if (nums[fast] != 0 && nums[slow] == 0) { 17 | swap(nums, slow, fast); 18 | slow++; 19 | } else { 20 | fast++; 21 | } 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/BubbleSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class BubbleSort { 8 | static List bubbleSort(List arr) { 9 | int n = arr.size(); 10 | for (int i = 0; i < n-1; i++) { 11 | boolean swap = false; 12 | for (int j = 0; j < n - 1; j++) { 13 | if (arr.get(j) > arr.get(j+1)) { 14 | Collections.swap(arr, j, j+1); 15 | swap = true; 16 | } 17 | } 18 | if(!swap) { 19 | break; 20 | } 21 | } 22 | return arr; 23 | } 24 | 25 | public static void main(String[] args) { 26 | System.out.println(bubbleSort(Arrays.asList(5,1,2,3,4))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/DS/Class5_Arrays/BinarySearch/FirstBadVersion.java: -------------------------------------------------------------------------------- 1 | package DS.Class5_Arrays.BinarySearch; 2 | 3 | 4 | public class FirstBadVersion { 5 | static boolean isBadVersion(int n) { 6 | if (n >= 4) { 7 | System.out.println(n); 8 | return true; 9 | } 10 | System.out.println(false); 11 | return false; 12 | } 13 | 14 | static int firstBadVersion(int n) { 15 | int left = 1, right = n; 16 | 17 | while(left < right) { 18 | int mid = left + (right - left)/ 2; 19 | System.out.println(mid); 20 | if(isBadVersion(mid)) right = mid; 21 | else left = mid + 1; 22 | System.out.println(left); 23 | } 24 | return left; 25 | } 26 | 27 | public static void main(String[] args) { 28 | firstBadVersion(5); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/InPlace/ReplaceElementswithGreatestElement.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array.InPlace; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ReplaceElementswithGreatestElement { 6 | public static int[] replaceElements(int[] nums) { 7 | int maxSoFar = -1; 8 | for (int i = nums.length - 1; i >= 0; i--) { 9 | if (maxSoFar < nums[i]) { 10 | int temp = nums[i]; 11 | nums[i] = maxSoFar; 12 | maxSoFar = temp; 13 | } else { 14 | nums[i] = maxSoFar; 15 | } 16 | } 17 | return nums; 18 | } 19 | 20 | public static void main(String[] args) { 21 | System.out.println(Arrays.toString( 22 | replaceElements( 23 | new int[]{17, 18, 5, 4, 6, 1})) 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/BitManipulation/HammingDistance.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.BitManipulation; 2 | 3 | public class HammingDistance { 4 | // Approach using inbuilt function 5 | public int hammingDistance(int x, int y) { 6 | return Integer.bitCount(x ^ y); 7 | } 8 | 9 | // My approach 10 | public int hammingDistance2(int x, int y) { 11 | int n = x ^ y; 12 | int count = 0; 13 | while(n > 0) { 14 | count++; 15 | n = n & n-1; 16 | } 17 | return count; 18 | } 19 | 20 | // Another approach using right shift to move through all the set bits 21 | public int hammingDistance3(int x, int y) { 22 | int n = x ^ y; 23 | int count = 0; 24 | while(n > 0) { 25 | count += n & 1; 26 | n = n >> 1; 27 | } 28 | return count; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/String/ReverseInteger.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.String; 2 | 3 | public class ReverseInteger { 4 | public static String reverseString(char[] s) { 5 | int lo = 0, hi = s.length-1; 6 | while(lo < hi) { 7 | char temp = s[lo]; 8 | s[lo] = s[hi]; 9 | s[hi] = temp; 10 | lo++; 11 | hi--; 12 | } 13 | return new String(s); 14 | } 15 | 16 | public static int reverse(int x) { 17 | String s = Integer.toString(x); 18 | char symbol; 19 | if(s.charAt(0) == '-' || s.charAt(0) == '+') { 20 | symbol = s.charAt(0); 21 | s = s.substring(1); 22 | } 23 | return x; 24 | } 25 | public static void main(String[] args) { 26 | // TODO : Complete this. Did this in JS as java string sucks balls 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/Conclusion/FindAllNumbersDisappeared.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array.Conclusion; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | // Ahha 8 | public class FindAllNumbersDisappeared { 9 | public static List findDisappearedNumbers(int[] nums) { 10 | List list = new ArrayList<>(); 11 | for (int i = 0; i < nums.length; i++) { 12 | nums[Math.abs(nums[i])-1] = Math.abs(nums[Math.abs(nums[i])-1]) * -1; 13 | } 14 | 15 | for (int i = 0; i < nums.length; i++) { 16 | if(nums[i] >= 0) { 17 | list.add(i+1); 18 | } 19 | } 20 | return list; 21 | } 22 | public static void main(String[] args) { 23 | System.out.println(findDisappearedNumbers(new int[]{4, 3, 2, 7, 8, 2, 3, 1}).toString()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/String/ReverseString2.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.String; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ReverseString2 { 6 | public static void reverseString(char[] s, int lo, int hi) { 7 | System.out.println("lo " + lo + " hi " + hi); 8 | while(lo < hi) { 9 | char temp = s[lo]; 10 | s[lo] = s[hi]; 11 | s[hi] = temp; 12 | lo++; 13 | hi--; 14 | } 15 | } 16 | public static String reverseStr(String s, int k) { 17 | char[] word = s.toCharArray(); 18 | for(int i = 0; i+k <= s.length(); i += k) { 19 | reverseString(word, i, i+k-1); 20 | } 21 | return new String(word); 22 | } 23 | 24 | public static void main(String[] args) { 25 | System.out.println(reverseStr("abcdefg", 2)); 26 | } 27 | // TODO: Can't comprehend the question, do it later 28 | } 29 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/MergeTwoSortedList.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList; 2 | 3 | import Implementation.LinkedList.ListNode; 4 | 5 | public class MergeTwoSortedList { 6 | static ListNode mergeTwoLists(ListNode l1, ListNode l2) { 7 | ListNode head = new ListNode(0); 8 | ListNode handler = head; 9 | 10 | while(l1 != null && l2 != null) { 11 | if(l1.val < l2.val) { 12 | handler.next = l1; 13 | l1 = l1.next; 14 | } else { 15 | handler.next = l2; 16 | l2 = l2.next; 17 | } 18 | handler = handler.next; 19 | } 20 | 21 | if(l1 == null) { 22 | handler.next = l2; 23 | } else if (l2 == null) { 24 | handler.next = l1; 25 | } 26 | 27 | return head.next; 28 | } 29 | 30 | public static void main(String[] args) { 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/RotateArray.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | import java.util.Arrays; 4 | 5 | public class RotateArray { 6 | static void reverse(int[] nums,int start, int length) { 7 | length = length-1; 8 | for (int i = start; i < length; i++) { 9 | int temp = nums[i]; 10 | nums[i] = nums[length]; 11 | nums[length] = temp; 12 | length--; 13 | } 14 | } 15 | 16 | static void rotate(int[] nums, int k) { 17 | if (nums.length >= 1) { 18 | int length = nums.length; 19 | reverse(nums, 0,length-k); 20 | reverse(nums, length-k, length); 21 | reverse(nums, 0, length); 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | int[] array = {1,2,3,4,5,6,7}; 27 | int k = 3; 28 | rotate(array, k); 29 | System.out.println(Arrays.toString(array)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/MergeSortedArray.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | public class MergeSortedArray { 4 | static void merge(int[] nums1, int m, int[] nums2, int n) { 5 | int[] result = new int[m+n]; 6 | int index = 0, i = 0, j = 0; 7 | for (i = 0, j = 0; i < m && j < n; i++, j++) { 8 | if(nums1[i] < nums2[j]) { 9 | result[index] = nums1[i]; 10 | j--; 11 | index++; 12 | } else { 13 | result[index] = nums2[j]; 14 | i--; 15 | index++; 16 | } 17 | } 18 | 19 | while(i < m) { 20 | result[index] = nums1[i]; 21 | index++; 22 | } 23 | while(j < n) { 24 | result[index] = nums2[j]; 25 | index++; 26 | } 27 | nums1 = result.clone(); 28 | } 29 | public static void main(String[] args) { 30 | // TODO : Cop 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/DS/Class3_Math_Assignments/CountingPrime.java: -------------------------------------------------------------------------------- 1 | package DS.Class3_Math_Assignments; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class CountingPrime { 8 | static int SieveOfErastosis(int n) { 9 | List primes = Arrays.asList(new Boolean[n]); 10 | Collections.fill(primes, Boolean.TRUE); 11 | 12 | if (n <= 2) return 0; 13 | 14 | for (int i = 2; i <= Math.floor(Math.sqrt(n)); i++) { 15 | for (int j = 2; j*i <= n; j++) { 16 | primes.set(j*i, Boolean.FALSE); 17 | } 18 | } 19 | 20 | int count = 0; 21 | for (int i = 2; i < n; i++) { 22 | if(primes.get(i) == Boolean.TRUE) { 23 | count++; 24 | System.out.println(i); 25 | } 26 | } 27 | return count; 28 | } 29 | 30 | public static void main(String[] args) { 31 | SieveOfErastosis(2); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Educative/DSInJava/Array/MergeTwoSortedArrays.java: -------------------------------------------------------------------------------- 1 | package Educative.DSInJava.Array; 2 | 3 | import java.util.Arrays; 4 | 5 | public class MergeTwoSortedArrays { 6 | static int[] mergeArrays(int[] nums1, int[] nums2) { 7 | int length = nums1.length + nums2.length; 8 | int[] result = new int[length]; 9 | int pointer1 = 0; 10 | int pointer2 = 0; 11 | for (int i = 0; i < length; i++) { 12 | if (pointer1 == nums1.length) result[i] = nums2[pointer2++]; 13 | else if (pointer2 == nums2.length) result[i] = nums1[pointer1++]; 14 | else if (nums1[pointer1] < nums2[pointer2]) result[i] = nums1[pointer1++]; 15 | else result[i] = nums2[pointer2++]; 16 | } 17 | return result; 18 | } 19 | 20 | public static void main(String[] args) { 21 | int[] arr1 = {1, 3, 4, 5}; 22 | int[] arr2 = {2, 6, 7, 8}; 23 | System.out.println(Arrays.toString(mergeArrays(arr1, arr2))); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/InPlace/SortArrayByParity.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array.InPlace; 2 | 3 | public class SortArrayByParity { 4 | public static void swap(int[] nums, int i, int j) { 5 | int temp = nums[i]; 6 | nums[i] = nums[j]; 7 | nums[j] = temp; 8 | } 9 | 10 | public static int[] sortArrayByParity(int[] nums) { 11 | for (int i = 0, j = nums.length-1; i < j;) { 12 | // In case both pointers are even 13 | if(nums[i] % 2 == 0 && nums[j] % 2 == 0) { 14 | i++; 15 | // In case i is odd and j is even swap 'em 16 | } else if (nums[i] % 2 != 0 && nums[j] % 2 == 0) { 17 | swap(nums, i, j); 18 | i++; 19 | j--; 20 | // Otherwise just bringing j back 21 | } else { 22 | j--; 23 | } 24 | } 25 | return nums; 26 | } 27 | 28 | public static void main(String[] args) { 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/QuickSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class QuickSort { 8 | static void quickSort(List arr, int lo, int hi) { 9 | if(lo arr, int lo, int hi) { 16 | int pivot = arr.get(hi-1); 17 | int i = lo-1; 18 | for (int j = lo; j < hi; j++) 19 | if (arr.get(j) < pivot) 20 | Collections.swap(arr, arr.get(++i), arr.get(j)); 21 | Collections.swap(arr, arr.get(++i), arr.get(hi)); 22 | return i; 23 | } 24 | 25 | public static void main(String[] args) { 26 | List arr= Arrays.asList(0,5,3,4,2,1); 27 | quickSort(arr, 0, 6); 28 | System.out.println(arr); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/TwoPointer/Cycle2.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList.TwoPointer; 2 | 3 | import Implementation.LinkedList.ListNode; 4 | 5 | public class Cycle2 { 6 | public ListNode detectCycle(ListNode head) { 7 | ListNode slow = head; 8 | ListNode fast = head; 9 | 10 | while (slow != null && fast != null && fast.next != null) { 11 | slow = slow.next; 12 | fast = fast.next.next; 13 | if (slow == fast) { 14 | slow = head; 15 | // Ahha Moment: When you found the intersection point reset the slow to head. 16 | // Now move both pointer one by one only. Wherever they intersect again, that's the beginning 17 | while(slow != fast) { 18 | slow = slow.next; 19 | fast = fast.next; 20 | } 21 | return slow; 22 | } 23 | } 24 | return null; 25 | } 26 | } 27 | 28 | // Require Review and reason behind the intuitiveness. 29 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting_Assignments/Sort_Colors.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting_Assignments; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Sort_Colors { 6 | static void sortColors(int[] nums) { 7 | int onesCount = 0, twosCount = 0, zerosCount = 0; 8 | for (int i = 0; i < nums.length; i++) { 9 | if (nums[i] == 0) { 10 | zerosCount++; 11 | } else if (nums[i] == 1) { 12 | onesCount++; 13 | } else { 14 | twosCount++; 15 | } 16 | } 17 | 18 | for (int i = 0; i < nums.length; i++) { 19 | if (zerosCount > 0) { 20 | zerosCount--; 21 | nums[i] = 0; 22 | } else if (onesCount > 0) { 23 | onesCount--; 24 | nums[i] = 1; 25 | } else { 26 | nums[i] = 2; 27 | } 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | int[] nums = {2,0,2,1,1,0}; 33 | sortColors(nums); 34 | System.out.println(Arrays.toString(nums)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/RemoveElement.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | public class RemoveElement { 4 | public static void removeAt(int index, int[] nums, int count) { 5 | for (int i = index; i < nums.length-count; i++) { 6 | nums[i] = nums[i+1]; 7 | } 8 | } 9 | 10 | public static int removeElement(int[] nums, int val) { 11 | int count = 0; 12 | for (int i = 0; i < nums.length-count; i++) { 13 | if(nums[i] == val) { 14 | System.out.println(i); 15 | count++; 16 | removeAt(i, nums, count); 17 | i--; 18 | } 19 | } 20 | return nums.length-count; 21 | } 22 | 23 | public static void main(String[] args) { 24 | int[] nums = {0,1,2,2,3,0,4,2}; 25 | System.out.println(removeElement(nums, 2)); 26 | } 27 | } 28 | 29 | // Ahha Moment -> While left shifting you should remember that you can copy a value from i+1 pos which needs 30 | // be deleted and if you increment the pointer you will be left with a value which needs to be deleted but somehow got 31 | // skipped -------------------------------------------------------------------------------- /src/Leetcode/Practice/TwoPointer/SquareSortedArray.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.TwoPointer; 2 | 3 | import java.util.Arrays; 4 | 5 | public class SquareSortedArray { 6 | public static final void swap (int[] a, int i, int j) { 7 | int t = a[i]; 8 | a[i] = a[j]; 9 | a[j] = t; 10 | } 11 | 12 | static int[] sortedSquares(int[] nums) { 13 | 14 | for (int i = 0; i < nums.length; i++) { 15 | nums[i] = Math.abs(nums[i]); 16 | } 17 | for (int i = 0, j = nums.length-1; i <= j; ) { 18 | if(nums[i] > nums[j]) { 19 | swap(nums, i, j); 20 | } 21 | j--; 22 | } 23 | 24 | for (int i = 0; i < nums.length; i++) { 25 | nums[i] = nums[i]*nums[i]; 26 | } 27 | return nums; 28 | }; 29 | 30 | 31 | public static void main(String[] args) { 32 | System.out.println(Arrays.toString(sortedSquares(new int[]{-4, -3, -1, 0, 3, 10}))); 33 | System.out.println(Arrays.toString(sortedSquares(new int[]{-7,-3,2,3,11}))); 34 | System.out.println(Arrays.toString(sortedSquares(new int[]{-10,-9, -8, -7}))); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/ValidMountain.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | public class ValidMountain { 4 | public boolean validMountainArray(int[] nums) { 5 | boolean result = false; 6 | String state = "INITIAL"; 7 | for (int i = 0; i < nums.length-1; i++) { 8 | // FROM Initial State -> Only two possible state (INC, DEC, SAME) 9 | if(nums[i] > nums[i+1] && state == "INITIAL") { 10 | result = false; 11 | break; 12 | } else if (nums[i] == nums[i+1]) { 13 | result = false; 14 | break; 15 | } 16 | if(nums[i] < nums[i+1] && state == "INITIAL") state = "INC"; 17 | 18 | // FROM INC state -> Three possible state (INC, DEC, Same) 19 | if(nums[i] > nums[i+1] && state == "INC" && i != 0) { 20 | state = "DEC"; 21 | result = true; 22 | } else if (nums[i] < nums[i+1] && state == "DEC") { 23 | result = false; 24 | break; 25 | } 26 | } 27 | return result; 28 | } 29 | 30 | public static void main(String[] args) { 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/DS/Class4_Sorting/InsertionSort.java: -------------------------------------------------------------------------------- 1 | package DS.Class4_Sorting; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class InsertionSort { 7 | static List insertionSort(List arr) { 8 | // We will start from i = 1 to n and will pick each element 1 at a time 9 | for (int i = 1; i < arr.size(); i++) { 10 | // We are starting from 1st position assuming 0 is already in sorted array 11 | int key = i; 12 | // The picked element is value and we will place it in our sorted region of the array. 13 | int value = arr.get(i); 14 | 15 | // This loop will shift all value to the right in sorted array and eventually will 16 | // terminate at the position where our new element will be placed. 17 | while (key > 0 && arr.get(key-1) > value) { 18 | arr.set(key, arr.get(key-1)); 19 | key--; 20 | } 21 | // Putting the new value to its correct position in sorted array. 22 | arr.set(key, value); 23 | } 24 | return arr; 25 | }; 26 | 27 | public static void main(String[] args) { 28 | System.out.println(insertionSort(Arrays.asList(0,5,3,4,2,1))); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/RemoveNthNode.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList; 2 | 3 | import Implementation.LinkedList.ListNode; 4 | 5 | public class RemoveNthNode { 6 | public ListNode removeNthFromEnd(ListNode head, int n) { 7 | int length = 0, pos = n; 8 | ListNode temp = head; 9 | 10 | // Count the length 11 | while(temp != null) { 12 | length++; 13 | temp = temp.next; 14 | } 15 | 16 | // Reset the head 17 | temp = head; 18 | // Normalise n with respect to length. if length is 5 and n = 2 remove (5-2)->next element 19 | pos = length - n; 20 | 21 | // Making the node stop 1 place before target node 22 | while(pos-- > 1) { 23 | temp = temp.next; 24 | } 25 | 26 | // Special case for list of length 1 27 | if (n == length && n == 1) head = null; 28 | 29 | // If we have to remove the last node 30 | else if(n == 1) temp.next = null; 31 | 32 | // if we have to remove the first node 33 | else if (n == length) head = head.next; 34 | 35 | // if we have to remove anything in between 36 | else temp.next = temp.next.next; 37 | 38 | return head; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/TwoPointer/IntersectionOfTwoList.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList.TwoPointer; 2 | 3 | import Implementation.LinkedList.ListNode; 4 | 5 | public class IntersectionOfTwoList { 6 | 7 | public ListNode getIntersectionNode(ListNode headA, ListNode headB) { 8 | ListNode temp1 = headA; 9 | ListNode temp2 = headB; 10 | 11 | int length1 = 0, length2 = 0; 12 | while(temp1 != null) { 13 | length1++; 14 | temp1 = temp1.next; 15 | } 16 | 17 | while(temp2 != null) { 18 | length2++; 19 | temp2 = temp2.next; 20 | } 21 | 22 | temp1 = headA; 23 | temp2 = headB; 24 | 25 | int difference = Math.abs(length1-length2); 26 | if (length1 > length2) { 27 | while(difference-- > 0) { 28 | temp1 = temp1.next; 29 | } 30 | } else { 31 | while(difference-- > 0) { 32 | temp2 = temp2.next; 33 | } 34 | } 35 | 36 | while(temp1 != null) { 37 | if(temp1 == temp2) return temp1; 38 | temp1 = temp1.next; 39 | temp2 = temp2.next; 40 | } 41 | return null; 42 | } 43 | } 44 | 45 | // OPTIMIZATION: DO IT WITHOUT TAKING A DIFFERENCE -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/RemoveDuplicate.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | import java.util.Arrays; 4 | 5 | /* 6 | Approach: 7 | - Take two pointers fast and slow. both start at 0 8 | - Fast will move forward and look for duplicates, if encountered it will keep moving forward until it reaches non duplicate 9 | - Replace the next element to slow pointer with the non duplicate. 10 | - Now fast will start looking for duplicate of this pointer. keep doing it until fast reach till the end. 11 | */ 12 | public class RemoveDuplicate { 13 | 14 | public static int removeDuplicates(int[] nums) { 15 | int fast = 0, slow = 0, count=0; 16 | boolean duplicate = false; 17 | for(slow = 0; fast < nums.length; fast++) { 18 | if(nums[slow] == nums[fast] && fast != slow) 19 | duplicate = true; 20 | if(nums[slow] != nums[fast] && duplicate) { 21 | slow++; 22 | count++; 23 | nums[slow] = nums[fast]; 24 | } 25 | if(!duplicate) { 26 | slow = fast; 27 | } 28 | System.out.println(slow); 29 | } 30 | return slow; 31 | } 32 | 33 | public static void main(String[] args) { 34 | int[] nums = {0,8}; 35 | System.out.println(removeDuplicates(nums)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/BinarySearch/FirstAndLast.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.BinarySearch; 2 | // Problem Reference : https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ 3 | 4 | public class FirstAndLast { 5 | public static int lowerBound(int[] arr, int target) { 6 | int lo = 0, hi = arr.length-1, result = -1; 7 | while (lo <= hi) { 8 | int mid = lo + (hi-lo) / 2; 9 | if (arr[mid] >= target) { 10 | hi = mid-1; 11 | } 12 | else lo = mid+1; 13 | if(arr[mid] == target) result = mid; 14 | } 15 | return result; 16 | }; 17 | 18 | public static int upperBound(int[] arr, int target) { 19 | int lo = 0, hi = arr.length-1, result = -1; 20 | while (lo <= hi) { 21 | int mid = lo + (hi-lo) / 2; 22 | if (arr[mid] <= target) { 23 | lo = mid+1; 24 | } 25 | else 26 | hi = mid-1; 27 | if(arr[mid] == target) result = mid; 28 | } 29 | return result; 30 | }; 31 | 32 | 33 | public static void main(String[] args) { 34 | int lo = lowerBound(new int[]{1,1}, 1); 35 | int hi = upperBound(new int[]{1,1}, 1); 36 | System.out.println("lo = " + lo); 37 | System.out.println("hi = " + hi); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/RotateList.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList; 2 | 3 | import Implementation.LinkedList.ListNode; 4 | 5 | public class RotateList { 6 | static ListNode rotateRight(ListNode head, int k) { 7 | int length = 0; 8 | ListNode traveller = head; 9 | 10 | // Find the length 11 | while(traveller != null) { 12 | traveller = traveller.next; 13 | length++; 14 | } 15 | 16 | // Normalize the k for the length of the list. 17 | k = length % k; 18 | traveller = head; 19 | 20 | // Reach to the split point where the list should end after rotation 21 | for (int i = 1; i < length - (k+1); i++) { 22 | traveller = traveller.next; 23 | } 24 | 25 | // Get the splitPoint for later 26 | ListNode splitPoint = traveller; 27 | 28 | // Reach the end of the list 29 | while (traveller.next != null) { 30 | traveller = traveller.next; 31 | } 32 | 33 | // Join the end to the head so that rotation can happen 34 | traveller.next = head; 35 | 36 | // Start the next node as head of rotated list 37 | head = splitPoint.next; 38 | 39 | // Mark the splitPoint as the end of the rotated list 40 | splitPoint.next = null; 41 | return head; 42 | 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/DS/Class5_Arrays/readme.md: -------------------------------------------------------------------------------- 1 | ## Arrays and Patterns 2 | 3 | Topic Completed 4 | - [ ] Binary Search 5 | - [ ] Two Pointers 6 | - [ ] Sliding Window 7 | 8 | ### Binary Search 9 | 10 | Binary Search technique is a simple recursion technique to find a number in a sorted array. 11 | The concept is really simple you have an Array which you split into two regions, region where your target can exist 12 | and region where your target can not exist. 13 | In this way we keep reducing the search space into half until we run out of search space. 14 | 15 | #### Template for Binary Search 16 | ```python 17 | int binary_search(array) { 18 | bool condition(value) { 19 | pass 20 | } 21 | 22 | left, right = min(search_space), max(search_space) # could be [0, n], [1, n] etc. Depends on problem 23 | while left < right: 24 | mid = left + (right - left) // 2 25 | if condition(mid): 26 | right = mid 27 | else: 28 | left = mid + 1 29 | return left 30 | ``` 31 | 32 | #### Patterns for Binary Search 33 | - [ ] Problems where its Difficult to figure out if Binary Search can be applied 34 | - [ ] 35 | 36 | 37 | ### References 38 | [Leetcode Discuss Binary Search Template](https://leetcode.com/discuss/study-guide/786126/Python-Powerful-Ultimate-Binary-Search-Template.-Solved-many-problems) 39 | [Binary Search for Beginners](https://leetcode.com/discuss/general-discussion/691825/Binary-Search-for-Beginners-Problems-or-Patterns-or-Sample-solutions) 40 | [Sliding Window for Beginners](https://leetcode.com/discuss/general-discussion/657507/sliding-window-for-beginners-problems-template-sample-solutions/562721) 41 | -------------------------------------------------------------------------------- /src/Implementation/Queue/Queue.java: -------------------------------------------------------------------------------- 1 | package Implementation.Queue; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Queue { 6 | private int max = 100; 7 | ArrayList arr = new ArrayList(); 8 | private int front = 0, size = 0, end = 0; 9 | 10 | public void enqueue(E x) { 11 | if(isFull()) { 12 | throw new RuntimeException("Queue is full"); 13 | } else { 14 | arr.add(front, x); 15 | front = (front+1) % max; 16 | size++; 17 | } 18 | } 19 | 20 | public void dequeue() { 21 | if(isEmpty()) 22 | throw new RuntimeException("Queue is Empty"); 23 | else { 24 | end = (end+1) % max; 25 | size--; 26 | } 27 | } 28 | 29 | public E peek() { 30 | if(isEmpty()) throw new RuntimeException("Queue is Empty"); 31 | return (E) arr.get(end); 32 | } 33 | 34 | int size() { 35 | return size; 36 | } 37 | 38 | boolean isFull() { 39 | return size() == max; 40 | } 41 | 42 | boolean isEmpty() { 43 | return size() == 0; 44 | } 45 | 46 | public static void main(String[] args) { 47 | Queue queue = new Queue<>(); 48 | 49 | for(int i = 0; i < 50; i++) { 50 | queue.enqueue((int) (Math.random() * 100)); 51 | } 52 | for(int i = 0; i < 50; i++) { 53 | System.out.println(queue.peek()); 54 | queue.dequeue(); 55 | } 56 | 57 | 58 | // Check whether the queue can hold more than 100 values. 59 | for(int i = 0; i < 60; i++) { 60 | queue.enqueue((int) (Math.random() * 100)); 61 | } 62 | for(int i = 0; i < 60; i++) { 63 | System.out.println(queue.peek()); 64 | System.out.println(queue.size()); 65 | queue.dequeue(); 66 | } 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/Array/TwoSum.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.Array; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | 6 | public class TwoSum { 7 | static int[] twoSum(int[] nums, int target) { 8 | int[] result = new int[2]; 9 | int[] clone = nums.clone(); 10 | Arrays.sort(clone); 11 | int i = 0, j = clone.length-1; 12 | // Find the two elements whose sum is equal to the target 13 | while(i < j) { 14 | if(clone[i] + clone[j] > target) { 15 | j--; 16 | } else if (clone[i] + clone[j] < target) { 17 | i++; 18 | } else { 19 | result = new int[]{clone[i], clone[j]}; 20 | break; 21 | } 22 | } 23 | 24 | // Found the first and second index in the original array. 25 | /* 26 | Taking care of 2 scenarios 27 | - In case first element and second element are same so they don't have same indexes. 28 | - In case the index found is equal to another element and therefore as a side-effect updating to another index. 29 | */ 30 | boolean zeroFound = false, firstFound = false; 31 | for (int k = 0; k < nums.length; k++) { 32 | if(result[0] == nums[k] && !zeroFound) { 33 | result[0] = k; 34 | zeroFound = true; 35 | } 36 | if((result[1] == nums[k]) && !firstFound) { 37 | result[1] = k; 38 | firstFound = true; 39 | } 40 | if(zeroFound && firstFound) break; 41 | } 42 | System.out.println(Arrays.toString(result)); 43 | 44 | if(result[0] == result[1]) { 45 | int value = nums[result[0]]; 46 | for (int k = 0; k < nums.length; k++) { 47 | if(value == nums[k] && result[1] != k) { 48 | result[1] = k; 49 | } 50 | } 51 | } 52 | 53 | return result; 54 | } 55 | 56 | static int[] twoSumMap(int[] nums, int target) { 57 | HashMap map = new HashMap<>(); 58 | int[] result = new int[2]; 59 | map.put(0, nums[0]); 60 | for (int i = 1; i < nums.length; i++) { 61 | if (map.get(i) == target - map.get(i)) { 62 | //TODO: Complete this 63 | } 64 | } 65 | return result; 66 | } 67 | public static void main(String[] args) { 68 | // System.out.println(Arrays.toString(twoSum(new int[]{1, 3, 4, 2},6))); 69 | System.out.println(Arrays.toString(twoSum(new int[]{3,2,3},6))); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Leetcode/Practice/LinkedList/LinkedList.java: -------------------------------------------------------------------------------- 1 | package Leetcode.Practice.LinkedList; 2 | 3 | public class LinkedList { 4 | 5 | // Define a Structure for Node 6 | class Node { 7 | int val; 8 | Node next; 9 | Node() {} 10 | Node(int val) { this.val = val; } 11 | Node(int val, Node next) { this.val = val; this.next = next; } 12 | } 13 | 14 | 15 | int val; 16 | int size = 0; 17 | Node head, tail; 18 | 19 | 20 | /** Initialize your data structure here. */ 21 | LinkedList(int val) { 22 | this.val = val; 23 | this.head = null; 24 | this.tail = null; 25 | } 26 | 27 | 28 | /** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */ 29 | public int get(int i) { 30 | if(this.size == 0 && this.size < i) return -1; 31 | else { 32 | Node temp = head; 33 | while(i-- > 0) { 34 | temp = temp.next; 35 | } 36 | return temp.val; 37 | } 38 | } 39 | 40 | public Node getNode(int index) { 41 | if(this.size == 0 && this.size < index) return null; 42 | else { 43 | Node temp = head; 44 | while(index-- > 0) { 45 | temp = temp.next; 46 | } 47 | return temp; 48 | } 49 | } 50 | 51 | 52 | /** Add a node of value val before the first element of the linked list. After the insertion, 53 | * the new node will be the first node of the linked list. */ 54 | public void addAtHead(int val) { 55 | Node node = new Node(val); 56 | if(this.size == 0) { 57 | this.head = node; 58 | this.tail = node; 59 | } else { 60 | node.next = head; 61 | head = node; 62 | } 63 | } 64 | 65 | /** Append a node of value val to the last element of the linked list. */ 66 | public void addAtTail(int val) { 67 | if(this.size == 0) { 68 | addAtHead(val); 69 | } else { 70 | Node node = new Node(val); 71 | this.tail.next = node; 72 | node.next = null; 73 | this.tail = node; 74 | } 75 | 76 | } 77 | 78 | /** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, 79 | * the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */ 80 | public void addAtIndex(int index, int val) { 81 | if(this.size != 0 && this.size > index) { 82 | Node node = new Node(val); 83 | Node prev = getNode(index-1); 84 | node = prev.next; 85 | } 86 | } 87 | 88 | /** Delete the index-th node in the linked list, if the index is valid. */ 89 | public void deleteAtIndex(int index) { 90 | 91 | } 92 | 93 | // TODO : Finish implementing Linked List 94 | 95 | } 96 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Sufferings and Problem Solving 3 | 4 | ## 1. Table of Content 5 | 6 | * 1. [Table of Content](#TableofContent) 7 | * 2. [Data Structures Implementation](#DataStructuresImplementation) 8 | * 2.1. [Common DS Implementation](#CommonDSImplementation) 9 | * 2.2. [Common Algo Implementation](#CommonAlgoImplementation) 10 | * 2.3. [Leetcode Explore](#LeetcodeExplore) 11 | * 3. [Algo Monster](#AlgoMonster) 12 | * 3.1. [Topics in Algo Monster](#TopicsinAlgoMonster) 13 | * 3.1.1. [Practice from Algo Monster](#PracticefromAlgoMonster) 14 | * 4. [Grokking the Coding Interview](#GrokkingtheCodingInterview) 15 | * 4.1. [Patterns](#Patterns) 16 | * 5. [Grokking Dynamic Programming Patterns](#GrokkingDynamicProgrammingPatterns) 17 | * 5.1. [Patterns](#Patterns-1) 18 | * 6. [System Design](#SystemDesign) 19 | * 7. [Daily Logs](#DailyLogs) 20 | 21 | 25 | 26 | **Refrences**: 27 | - Guided Study 28 | [Algo Monster](https://algo.monster/problems/stats) 29 | [Grokking the Coding Interview](https://www.educative.io/courses/grokking-the-coding-interview) 30 | 31 | - Extreme Practice in Adhoc Manner (Monthly Challenge) 32 | [LeetCode Challenge](https://leetcode.com/) 33 | - LeetCode Lists 34 | - [Blind 75 must do](https://leetcode.com/list/#) 35 | - [Amazon must do](https://leetcode.com/list?selectedList=xtwvgjdm) 36 | - [Must do easy](https://leetcode.com/list?selectedList=xim6v1k2) 37 | - [Must do medium](https://leetcode.com/list?selectedList=xi2eg5at) 38 | - [Amazon Question - GeeksforGeeks](https://practice.geeksforgeeks.org/explore/?company%5B%5D=Amazon&problemType=functional&page=1&sortBy=submissions&company%5B%5D=Amazon) 39 | 40 | - LeetCode Study Guide on Various DS 41 | - [Leetcode Concepts Breakdown](https://leetcode.com/discuss/study-guide/1476329/Useful-posts-from-LeetCode-discussions-for-personal-use-and-concept-revision) 42 | - Object Oriented Programming 43 | - [Grokking Object Oriented Programming Interview](https://www.educative.io/courses/grokking-the-object-oriented-design-interview) 44 | - [Udit Agarwal LLD Playlist](https://www.youtube.com/c/anomaly2104) 45 | 46 | - Dynamic Programming and Trees + Graph (More Practice) 47 | - [Grokking Dynamic Programming Problems](https://www.educative.io/courses/grokking-dynamic-programming-patterns-for-coding-interviews) 48 | 49 | - Quick Glance for Practiced Questions 50 | - [ALGO-DS Quick Cheat Sheet](https://github.com/sherxon/AlgoDS) 51 | 52 | **Study Approach** 53 | - Practice and Study consistently. No Streak breaks 54 | - Create Flashcards daily. 55 | - Spend 1-2 hour [synthesizing whatever](https://leetcode.com/discuss/career/449135/How-to-effectively-use-LeetCode-to-prepare-for-interviews) you learn. 56 | - List down all the [aha moments](https://leetcode.com/discuss/interview-question/1367198/You-Only-Have-To-Be-Right-Once%3A-Facebook-Offer/1030106) in one file. 57 | - Practice Java / Create Projects in JAVA 58 | - Reserve time for writing notes and practicing flashcards 59 | 60 | > NOT TODO LIST 61 | - Block all the social media permanently. 62 | - Don't get distracted by any other technology 63 | - Don't start learning anything new 64 | - No for CSS 65 | - No for any new JS framework 66 | - No for any tool 67 | - No for Design 68 | 69 | ## 2. Data Structures Implementation 70 | 71 | ### 2.1. Common DS Implementation 72 | - [x] Stack 73 | - [x] Queue 74 | - [ ] Linked List 75 | - [ ] Doubly Linked List 76 | - [ ] Hashmap 77 | - [ ] Tree 78 | - [ ] Tree Implementation 79 | - [ ] Inorder 80 | - [ ] Recursive 81 | - [ ] Iterative 82 | - [ ] Preorder 83 | - [ ] Recursive 84 | - [ ] Iterative 85 | - [ ] PostOrder 86 | - [ ] Recursive 87 | - [ ] Iterative 88 | - [ ] AVL Tree 89 | - [ ] Trie 90 | - [ ] Hased Array Tree 91 | - [ ] LRU Cache 92 | - [ ] Graph 93 | - [ ] BFS 94 | - [ ] DFS 95 | 96 | ### 2.2. Common Algo Implementation 97 | - [ ] Sorting 98 | - [ ] Binary 99 | - [ ] Selection 100 | - [ ] Insertion 101 | - [ ] Quick 102 | - [ ] Merge 103 | - [ ] Counting 104 | - [ ] Radix 105 | - [ ] Bucket 106 | - [ ] Heap 107 | - [ ] Search 108 | - [ ] Binary Search 109 | - [ ] Lower Bound 110 | - [ ] Upper Bound 111 | - [ ] Binary Search on Ranges 112 | - [ ] String 113 | - [ ] Rabin Karp 114 | 115 | ### 2.3. Leetcode Explore 116 | 117 | **Array** 118 | - [x] [Duplicate Zeroes](https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3245/) 119 | - [ ] [Merge Sorted Arrays](https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/) 120 | - [x] [Valid Mountain Array](https://leetcode.com/explore/learn/card/fun-with-arrays/527/searching-for-items-in-an-array/3251/) 121 | - [x] [Check if N and Its double Exist](https://leetcode.com/explore/learn/card/fun-with-arrays/527/searching-for-items-in-an-array/3250/) 122 | - [x] [Remove Duplicate From Sorted Array](https://leetcode.com/explore/learn/card/fun-with-arrays/526/deleting-items-from-an-array/3248/) 123 | - [x] [Array Deletions](https://leetcode.com/explore/learn/card/fun-with-arrays/526/deleting-items-from-an-array/3246/) 124 | - [x] In Place Operations 125 | - [x] [Replace Elements with Greatest Elements on Right Side](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/3257/) 126 | - [x] [Remove Duplicates from Sorted Array](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/3258/) 127 | - [x] [Move Zeroes](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/3157/) 128 | - [x] [Sort Array By Parity](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/3260/) 129 | - [x] [Remove Element](https://leetcode.com/explore/learn/card/fun-with-arrays/511/in-place-operations/3575/) 130 | - [ ] Conclusion 131 | - [x] [Height Checker](https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3228/) 132 | - [ ] [Third Maximum Number](https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3231/) 133 | - [ ] [Find all Numbers Disappeared in Array](https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3270/) 134 | - [ ] [Squares of Sorted Array](https://leetcode.com/explore/learn/card/fun-with-arrays/523/conclusion/3574/) 135 | 136 | ## 3. Algo Monster 137 | ### 3.1. Topics in Algo Monster 138 | - [ ] Binary Search 139 | - [ ] Depth First Search 140 | - [ ] Backtracking 141 | - [ ] Breadth First Search 142 | - [ ] Graph 143 | - [ ] Two pointers 144 | - [ ] Priority Queue 145 | - [ ] Dynamic Programming 146 | - [ ] Divide and Conquer 147 | - [ ] Advanced Data Structure 148 | - [ ] Other 149 | 150 | #### 3.1.1. Practice from Algo Monster 151 | - [ ] Object Oriented Design 152 | - [ ] Amazon Online Assessment 153 | - [ ] Microsoft Online Assessment 154 | - [ ] Google Online Assessment 155 | - [ ] Twitter Online Assessment 156 | 157 | ## 4. Grokking the Coding Interview 158 | ### 4.1. Patterns 159 | - [ ] Sliding Window 160 | - [ ] Two Pointers 161 | - [ ] Fast and Slow Pointers 162 | - [ ] Merge Intervals 163 | - [ ] Cyclic Sort 164 | - [ ] In-place reversal of Linked List 165 | - [ ] Tree: Breadth First Search 166 | - [ ] Tree: Depth First Search 167 | - [ ] Two Heaps 168 | - [ ] Subsets 169 | - [ ] Modified Binary Search 170 | - [ ] Bitwise XOR 171 | - [ ] Top K Element 172 | - [ ] K-way merge 173 | - [ ] 0-1 Knapsack 174 | - [ ] Topological Sort 175 | - [ ] Miscellaneous 176 | 177 | ## 5. Grokking Dynamic Programming Patterns 178 | ### 5.1. Patterns 179 | - [ ] Knapsack 180 | - [ ] Unbounded Knapsack 181 | - [ ] Fibonacci Numbers 182 | - [ ] Palindromic Subsequence 183 | - [ ] Longest Common Substring 184 | 185 | ## 6. System Design 186 | **Reference** : 187 | [List of Questions asked on System Design](https://leetcode.com/discuss/interview-question/1140451/Helpful-list-of-LeetCode-Posts-on-System-Design-at-Facebook-Google-Amazon-Uber-Microsoft) 188 | 189 | ## 7. Daily Logs 190 | | Day Count | Source | Problem | Level | Time | Notes | Solution | Category | R - 1 | R - 2 | R - 3 | R - 4 | 191 | | --------- | ------ | ---------------------------------- | ----- | ---- | ----- | -------- | -------- | ----- | ----- | ----- | ----- | 192 | | 1 | | Implement Stack | Easy | 20 m | | | | | | | | 193 | | | | Implement Queue | Easy | 30 m | | | | | | | | 194 | | | | Duplicate Zeros | Easy | 20 m | | | | | | | | 195 | | 2 | | Valid Mountain Array | Easy | 30 m | | | | | | | | 196 | | | | Check if N and Its double Exist | Easy | 30 m | | | | | | | | 197 | | | | Remove Duplicate From Sorted Array | Easy | 30 m | | | | | | | | 198 | | | | Array Deletions | Easy | 30 m | | | | | | | | 199 | | | | Merge Sorted Arrays | | ❌ | | | | | | | | 200 | | 3 | | | | | | | | | | | | 201 | --------------------------------------------------------------------------------