├── 0001-two-sum ├── NOTES.md └── 0001-two-sum.java ├── src ├── Java │ ├── Random │ │ ├── Number Program │ │ │ ├── Natural │ │ │ ├── Number │ │ │ ├── Print digits of a number on different lines.java │ │ │ ├── Palindrome Number.java │ │ │ └── Natural Number Sum.java │ │ ├── Remove Duplicates from Sorted Array.java │ │ ├── Array │ │ │ ├── printArray.java │ │ │ └── Scanner Array input in java.java │ │ ├── check if the given number is a power of k .java │ │ ├── Recursion │ │ │ ├── MIn elements in array.java │ │ │ ├── print all occurance using recusion.java │ │ │ ├── first occurance of elements in array using recursion.java │ │ │ ├── searching in array.java │ │ │ ├── PrintArrayUsingRecursion.java │ │ │ ├── Palindrome Array using Recursion.java │ │ │ ├── Max Elements in array Using Recursion.java │ │ │ ├── last occurance elements in array using recursion.java │ │ │ └── Recursive sum till single digit.java │ │ ├── Factor Program │ │ │ ├── Prime Number.java │ │ │ ├── Deficient Number.java │ │ │ ├── Abundant Number.java │ │ │ ├── Composite Number.java │ │ │ ├── Perfect Number.java │ │ │ └── Pronic Number.java │ │ ├── Geometric Series sum.java │ │ ├── Divisible sum pair.md │ │ ├── Theory │ │ │ └── Factor , Product , devisior.txt │ │ └── Reverse digits of a Number.md │ ├── LeetCode │ │ ├── Jai Shree Ganesh.txt │ │ ├── mahadev.txt │ │ ├── Find Pivot Index.java │ │ ├── ReplaceElementswithGreatestElementonRightSide.java │ │ ├── Array │ │ │ ├── Contains Duplicate (n^2).java │ │ │ └── Remove Duplicates from Sorted Array.java │ │ └── Two Sum II - Input Array Is Sorted.md │ ├── Series │ │ ├── today │ │ │ ├── Array, String , Sorting │ │ │ │ ├── String Palindrome.java │ │ │ │ ├── Check Number Palindrome or not.java │ │ │ │ ├── ArmStrong Number.java │ │ │ │ └── Factorial iterative and Recursive.java │ │ │ ├── Delete Alternate Nodes Linked List.java │ │ │ ├── Square Root Of an Integer - L and Binary Search.java │ │ │ ├── GetNTH Node Linked List.java │ │ │ └── Linked List Length Even or Odd.java │ │ ├── OOPS │ │ │ └── getter setter │ │ │ │ ├── Student.java │ │ │ │ └── StudentUse.java │ │ ├── my practice │ │ │ ├── devision until 1.java │ │ │ ├── Find String Longest name.java │ │ │ ├── Find min & max Array using while loop.java │ │ │ └── Find min & max while Loop new Way.java │ │ ├── Factor Program │ │ │ ├── Prime Number.java │ │ │ ├── Deficient Number.java │ │ │ ├── Abundant Number.java │ │ │ ├── Composite Number.java │ │ │ ├── Perfect Number.java │ │ │ └── Pronic Number.java │ │ ├── String │ │ │ ├── String Length.java │ │ │ ├── find frequency of chracter in String.java │ │ │ ├── Duplicate Character 2nd way.java │ │ │ ├── Find Index of Character X In The Given String.java │ │ │ ├── palindrome String.java │ │ │ ├── Lower To Upper & Upper To Lower Case.java │ │ │ ├── Character Print Occur Multi Times In String.java │ │ │ ├── String Sum.java │ │ │ ├── Find Character X in given String.java │ │ │ ├── Panagram Checking Program.java │ │ │ ├── remove Duplicate.java │ │ │ └── String Anagram Or NOT.java │ │ ├── Number Program │ │ │ ├── Print digits of a number on different lines.java │ │ │ └── Palindrome Number.java │ │ ├── Searching │ │ │ ├── Linear Search In Array.java │ │ │ ├── Linear Searching IN Array 2.java │ │ │ ├── Linear Searching IN Array 2.txt │ │ │ ├── Array Count K Smaller Number.java │ │ │ └── Linear Searching In String Array.java │ │ ├── Function │ │ │ ├── Two Number Sum Using Function.java │ │ │ └── Doing Sum Of N Numbers Using For Loop With Function.java │ │ ├── Sorting │ │ │ └── InsertionSort.java │ │ ├── Others │ │ │ └── Check Number Palindrome or not.java │ │ └── Arrays │ │ │ ├── Array Rotation.java │ │ │ ├── max Frequency Given K elements in Array.java │ │ │ ├── README.md │ │ │ ├── Find First Index Of X In Arrays.java │ │ │ ├── non repeated elements O(n^2) Nested Loop with count.java │ │ │ └── Find The Last Index Of X in Arrays.java │ ├── Data Structure │ │ ├── Tree │ │ │ ├── Tree │ │ │ │ ├── Main.java │ │ │ │ ├── Node.java │ │ │ │ ├── IdenticalTree.java │ │ │ │ └── OLDBinaryTreeCreate.java │ │ │ └── Node.java │ │ └── LinkedList │ │ │ ├── Circular Linked List │ │ │ └── Main.java │ │ │ ├── Create LinkedList │ │ │ └── Node.java │ │ │ └── Doubly Linked List │ │ │ └── Main.java │ ├── GFG │ │ ├── WaveArray.java │ │ ├── Prime Number.java │ │ ├── Sum of Array .md │ │ ├── Find n-th term of series 1, 3, 6, 10, 15, 21.java │ │ ├── Second Largest.java │ │ ├── KthSmallestElement.java │ │ └── Print alternate elements of an array .md │ └── HackerRank │ │ ├── Mini-Max Sum.md │ │ └── Divisible Sum Pairs.md ├── SELF │ ├── week 1 │ │ ├── Recursion │ │ │ ├── searching using recursion .java │ │ │ ├── SumNumber.java │ │ │ ├── SumOfDigit.java │ │ │ ├── print all occurance using recursion.java │ │ │ ├── minimum elements in array using recursion .java │ │ │ ├── n number product using recursion.java │ │ │ ├── find 1st occurrences of elements in array using recursion.java │ │ │ ├── ReverseDigit Recursion.java │ │ │ ├── n%10 result.java │ │ │ ├── array print using recursion.java │ │ │ ├── sum until value less then single digit .java │ │ │ ├── Recursive sum until single degit.java │ │ │ ├── n number sum recursive.java │ │ │ ├── palindrome array using recursion .java │ │ │ ├── print last occurance in array using recursion.java │ │ │ ├── maximum elements using recursion (mY).java │ │ │ ├── dual function calling .java │ │ │ └── Check array sorted or not recursive appraoch.java │ │ ├── Random │ │ │ ├── sum.java │ │ │ ├── table create .java │ │ │ ├── swap two number and print.java │ │ │ ├── switch case conditional problem .java │ │ │ ├── sum of odd.java │ │ │ ├── count numbers frequency in numbers.java │ │ │ └── 2 way to print last index of the string built-in method and iterative.java │ │ ├── square number get.java │ │ ├── n equal to given k square.java │ │ ├── character ascii value.java │ │ ├── given number N square K get.java │ │ ├── String │ │ │ ├── String array split method.java │ │ │ ├── toUpperCase and toLowerCase String method in java .md │ │ │ ├── hey to heey String Question. dual the value e word .java │ │ │ └── reverse string.java │ │ ├── print % given k.java │ │ ├── average calculator.java │ │ ├── febbonaci series till 3.java │ │ ├── increment array program .java │ │ ├── Day in Month.java │ │ ├── print all digit of a number on different lines.java │ │ ├── even number sum and average.java │ │ ├── N power 2 .java │ │ ├── Reverse Digit.java │ │ ├── swtich case.java │ │ ├── Array Sum and Print .java │ │ ├── string high ascii value .java │ │ ├── Sum even number and count even number then sum both.java │ │ ├── 2D Matrix │ │ │ └── Sum2DArray.java │ │ ├── find minimum and then find moduler to all %.java │ │ ├── Prime Number N print .java │ │ ├── get Armstrong Number return true false.java │ │ ├── hcf of two number.java │ │ └── Armstrong number check.java │ ├── week 9 │ │ └── External │ │ │ ├── HashMap │ │ │ └── Easy │ │ │ │ └── Character Frequencies.java │ │ │ └── SubArray │ │ │ └── Medium │ │ │ └── Maximum Contiguous Subarray Sum.java │ ├── week 6 │ │ ├── Tree │ │ │ ├── HackerRank │ │ │ │ └── Height of a Binary Tree.java │ │ │ ├── Leetcode │ │ │ │ ├── bfs Kth Smallest Element in a BST.java │ │ │ │ └── Recursive Same Tree.java │ │ │ └── GFG │ │ │ │ ├── 2 Approach Sum of Binary Tree.java │ │ │ │ └── Inorder Traversal.java │ │ ├── Two Sum one pass hashmap.java │ │ ├── Leetcode │ │ │ └── Binary Search │ │ │ │ └── Search Insert Position.java │ │ └── Kadane Algo │ │ │ ├── Leetcode │ │ │ └── Maximum Subarray.java │ │ │ └── GFG │ │ │ └── Kadane's Algorithm.java │ ├── week 5 │ │ ├── Stack │ │ │ ├── Leetcode │ │ │ │ ├── Reverse String too bad time complexity using stack.java │ │ │ │ └── Reverse String using Two POinter and Stack.java │ │ │ └── RANDOM │ │ │ │ ├── Reverse String using stack time complexity too bad 346ms.java │ │ │ │ └── next Greater Element Brute force.java │ │ └── Binary Search │ │ │ └── GFG │ │ │ └── Square root of a number.java │ ├── week 4 │ │ ├── LinkedList GFG │ │ │ └── Easy GFG │ │ │ │ ├── Last index of One String Question.java │ │ │ │ ├── Check If Circular Linked List.java │ │ │ │ ├── Linked List Length Even or Odd.java │ │ │ │ └── Count nodes of linked list.java │ │ ├── Binary Search │ │ │ ├── Square root of a number.java │ │ │ └── binary search descending order.java │ │ └── Binary Search GFG │ │ │ └── Searching an element in a sorted array.java │ ├── Tips │ │ └── -'a' approach.java │ └── week 3 │ │ └── LinkedList │ │ └── Leetcode │ │ └── Middle of the Linked List.java ├── DSA Complete - Java │ ├── 02. Algorithms │ │ ├── 08. LinkedList │ │ │ ├── README.md │ │ │ ├── 10. Move LastE to first in LL │ │ │ │ └── README.md │ │ │ ├── 32. Delete given Node from LL │ │ │ │ └── README.md │ │ │ └── 20. Circular LL │ │ │ │ └── README.md │ │ ├── 02. Matrix │ │ │ └── 08. Common elements in all rows │ │ │ │ └── README.md │ │ ├── 03. Strings │ │ │ ├── 03. Print Duplicates │ │ │ │ └── README.md │ │ │ ├── 04. Check String Rotations │ │ │ │ └── README.md │ │ │ ├── 05. valid shuffle string │ │ │ │ └── README.md │ │ │ └── 12. Count Binary Substring LC-696 │ │ │ │ └── README.md │ │ ├── 09. Trees │ │ │ ├── 03. BinarySearchTrees │ │ │ │ ├── 13. Merge 2 BSTs GQ │ │ │ │ │ └── README.md │ │ │ │ ├── 07. Minimum Element in BST GQ │ │ │ │ │ └── README.md │ │ │ │ └── 05. Flatten BST to Sorted LL GQ │ │ │ │ │ └── README.md │ │ │ └── 02. BinaryTrees │ │ │ │ ├── 31. Maximum sum SubTree │ │ │ │ └── README.md │ │ │ │ └── 33. Minimum swaps req. to convert BT into BST │ │ │ │ └── README.md │ │ ├── 01. Arrays │ │ │ ├── 03. Sorting │ │ │ │ ├── 01. BubbleSort │ │ │ │ │ └── README.md │ │ │ │ ├── 02. InsertionSort │ │ │ │ │ └── README.md │ │ │ │ └── 03. SelectionSort │ │ │ │ │ └── README.md │ │ │ ├── 18. Best Time to Buy and Sell Stock │ │ │ │ ├── iii 123 │ │ │ │ │ └── README.md │ │ │ │ └── i 121 │ │ │ │ │ └── README.md │ │ │ ├── 01. Reverse Array │ │ │ │ └── README.md │ │ │ ├── 09. Kadane's Algorithm Problems │ │ │ │ └── README.md │ │ │ ├── 45. Minimize Difference of any K element │ │ │ │ └── README.md │ │ │ └── 06. NegativePositiveArray │ │ │ │ └── NegativePositiveArray.java │ │ ├── 10. Stack & Queue │ │ │ ├── 06. Baseball Game #682 │ │ │ │ └── Resources.md │ │ │ ├── 10. Make The String Great #1544 │ │ │ │ └── Resources.md │ │ │ ├── 18. Infix Prefix Postfix │ │ │ │ ├── 01. Infix to Postfix │ │ │ │ │ └── pseudocode.png │ │ │ │ ├── 02. Infix to Prefix │ │ │ │ │ └── pseudocode.png │ │ │ │ ├── 03. Postfix to Infix │ │ │ │ │ ├── pseudocode.png │ │ │ │ │ └── Resources.md │ │ │ │ ├── 04. Prefix to Infix │ │ │ │ │ ├── pseudocode.png │ │ │ │ │ └── Resources.md │ │ │ │ ├── 05. Postfix to Prefix │ │ │ │ │ ├── pseudocode.png │ │ │ │ │ └── Resources.md │ │ │ │ └── 06. Prefix to Postfix │ │ │ │ │ ├── pseudocode.png │ │ │ │ │ └── Resources.md │ │ │ ├── 05. Build an Array With Stack Operations #1441 │ │ │ │ └── Resources.md │ │ │ ├── 38. Game Of String │ │ │ │ └── README.md │ │ │ ├── 09. Crawler Log Folder #1598 │ │ │ │ ├── Resources.md │ │ │ │ ├── Solution_stack.java │ │ │ │ └── Solution_optimised.java │ │ │ ├── 13. Design a Stack With Increment Operation #1381 │ │ │ │ └── Readme.md │ │ │ ├── 11. Backspace String Compare #844 │ │ │ │ ├── Resources.md │ │ │ │ └── Editorial.java │ │ │ ├── 16. Score of Parentheses #856 │ │ │ │ ├── Resources.md │ │ │ │ └── Solution.java │ │ │ ├── 17. Validate Stack Sequences #946 │ │ │ │ ├── Resources.md │ │ │ │ └── Solution.java │ │ │ ├── 07. Next Greater Element I #496 │ │ │ │ ├── Resources.md │ │ │ │ └── Solution_Optimised.java │ │ │ ├── 15. Daily Temperature #739 │ │ │ │ └── Readme.md │ │ │ ├── 20. reverse a stack IMP │ │ │ │ └── README.md │ │ │ ├── 12. Valid Parentheses #20 │ │ │ │ └── README.md │ │ │ ├── 14. Minimum Add to Make Parentheses Valid #921 │ │ │ │ └── Readme.md │ │ │ ├── 21. sort a stack IMP │ │ │ │ └── README.md │ │ │ └── 08. Next Greater Element II #503 │ │ │ │ └── README.md │ │ ├── 06. DP │ │ │ └── 02. Qs │ │ │ │ ├── 40. count dearrangement │ │ │ │ └── README.md │ │ │ │ ├── 02. nPr │ │ │ │ └── README.md │ │ │ │ ├── 01. nCr │ │ │ │ └── README.md │ │ │ │ ├── 15. maximum sum inc subseq │ │ │ │ └── README.md │ │ │ │ ├── 19. max length chain │ │ │ │ └── README.md │ │ │ │ ├── 21. pair wt specific ele │ │ │ │ └── README.md │ │ │ │ ├── 17. long. subs-diff btw adj is 1 │ │ │ │ └── README.md │ │ │ │ └── 28. Kadane's algo │ │ │ │ └── README.md │ │ └── 07. Searching & Sorting │ │ │ └── 19. Missing Number in AP │ │ │ └── README.md │ ├── 01. DataStructures │ │ ├── 02. Stack │ │ │ ├── Basic Operation │ │ │ │ ├── 3. Stack using Queue │ │ │ │ │ └── Resources.md │ │ │ │ ├── 2. Stack using LinkList │ │ │ │ │ └── Resources.md │ │ │ │ └── 1. Stack using Array │ │ │ │ │ └── Resources.md │ │ │ ├── LeetCode Qs │ │ │ │ ├── 04. Baseball Game #682 │ │ │ │ │ └── Resources.md │ │ │ │ ├── 07. Make The String Great #1544 │ │ │ │ │ └── Resources.md │ │ │ │ ├── 01. Remove Outermost Parentheses #1021 │ │ │ │ │ └── Resources.md │ │ │ │ ├── 03. Build an Array With Stack Operations #1441 │ │ │ │ │ └── Resources.md │ │ │ │ ├── 02. Remove All Adjacent Duplicates In String #1047 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Solution_pranay.java │ │ │ │ ├── 06. Crawler Log Folder #1598 │ │ │ │ │ ├── Resources.md │ │ │ │ │ ├── Solution_stack.java │ │ │ │ │ └── Solution_optimised.java │ │ │ │ ├── 10. Design a Stack With Increment Operation #1381 │ │ │ │ │ └── Resources.md │ │ │ │ ├── 12. Daily Temperatures #739 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Solution.java │ │ │ │ ├── 08. Backspace String Compare #844 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Editorial.java │ │ │ │ ├── 13. Score of Parentheses #856 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Solution.java │ │ │ │ ├── 14. Validate Stack Sequences #946 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Solution.java │ │ │ │ ├── 09. Valid Parentheses #20 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Solution simple.java │ │ │ │ ├── 05. Next Greater Element I #496 │ │ │ │ │ └── Resources.md │ │ │ │ └── 11. Minimum Add to Make Parentheses Valid #921 │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── Solution.java │ │ │ └── Infix Prefix Postfix │ │ │ │ ├── 01. Infix to Postfix │ │ │ │ └── pseudocode.png │ │ │ │ ├── 02. Infix to Prefix │ │ │ │ └── pseudocode.png │ │ │ │ ├── 03. Postfix to Infix │ │ │ │ ├── pseudocode.png │ │ │ │ └── Resources.md │ │ │ │ ├── 04. Prefix to Infix │ │ │ │ ├── pseudocode.png │ │ │ │ └── Resources.md │ │ │ │ ├── 05. Postfix to Prefix │ │ │ │ ├── pseudocode.png │ │ │ │ └── Resources.md │ │ │ │ └── 06. Prefix to Postfix │ │ │ │ ├── pseudocode.png │ │ │ │ └── Resources.md │ │ ├── 03. Queue │ │ │ └── Basic Operations │ │ │ │ ├── 03. Queue using stacks │ │ │ │ └── Resources.md │ │ │ │ ├── 01. Queue using array │ │ │ │ └── pseudocode.png │ │ │ │ ├── 04. Circular Queue using array │ │ │ │ └── Resources.md │ │ │ │ ├── 02. Queue using linklist │ │ │ │ └── Resources.md │ │ │ │ ├── 06. Dequeue using circular array │ │ │ │ └── Resources.md │ │ │ │ └── 07. Priority Queue │ │ │ │ └── KLargestElement.java │ │ ├── 01. LinkList │ │ │ ├── 1. Singly-LinkList │ │ │ │ └── InterviewBit Qs │ │ │ │ │ ├── 12. Reverse LL-ii │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 03. Kth Node From Middle │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── solution.java │ │ │ │ │ ├── 11. Rotate LL by K place │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 04. Palindrome List GQ │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 01. ReverseLL │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── solution.java │ │ │ │ │ ├── 02. IntersectionOfLL │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 09. Add two no. as List │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 08. Remove nth Node from List end GQ │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 06. Remove Dublicate From Sorted List │ │ │ │ │ ├── Resources.md │ │ │ │ │ └── solution.java │ │ │ │ │ ├── 07. Remove Dublicate From Sorted List- II GQ │ │ │ │ │ └── Resources.md │ │ │ │ │ ├── 10. Reverse LL in K group GQ │ │ │ │ │ └── Resources.md │ │ │ │ │ └── 05. Merge Two Sorted List GQ │ │ │ │ │ └── Resources.md │ │ │ ├── 3. Circular-LinkList │ │ │ │ └── Resources.md │ │ │ └── 2. Doubly-LinkList │ │ │ │ ├── Basic Operations │ │ │ │ └── Resources.md │ │ │ │ └── Questions │ │ │ │ └── 1. Two Pair Sum │ │ │ │ └── 2 pair sum Q.pdf │ │ └── 07. Graphs │ │ │ └── README.md │ └── 03. LC Contest Practice │ │ └── 01. WC-287 │ │ └── 01. Min Num of Opr to Conv. Time #2224 │ │ └── README.md ├── Theory │ ├── Interview Tricky Question │ │ ├── .vscode │ │ │ └── settings.json │ │ └── Case&TypeConversion │ │ │ └── StringMethod.class │ └── Theory │ │ └── Factor , Product , devisior.txt ├── Python │ └── LeetCode │ │ ├── PalindromeNumber.md │ │ ├── Majority Element.py │ │ └── MajorityElement.md └── JavaScript │ └── LeetCode │ ├── Majority Element.js │ ├── Tree │ ├── Two Sum O(n^2).js │ └── Validate Binary Search Tree.js │ └── Binary Search │ └── Binary Search.js ├── Interview Ready Solution ├── Grind │ ├── readme.md │ ├── Grind 169 │ │ └── link.md │ ├── Grind 75 │ │ ├── link.md │ │ └── Blind 75 Must Do Leetcode │ │ │ └── link.md │ ├── Blind 75 Must Do Leetcode │ │ └── link.md │ ├── Leetcode │ │ ├── 60 questions to solve │ │ │ └── link.md │ │ ├── Comprehensive Data Structure and Algorithm Study Guide │ │ │ └── Link.md │ │ └── How to effectively use LeetCode to prepare for interviews!! │ │ │ └── link │ ├── GFG │ │ ├── Top 50 Array Coding Problems for Interviews │ │ │ └── link.md │ │ ├── Top 50 String Coding Problems for Interviews │ │ │ └── link.md │ │ ├── Practice for cracking any coding interview │ │ │ └── link.md │ │ └── Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, … │ │ │ └── link.md │ └── 14 Patterns to Ace Any Coding Interview Question │ │ └── link.md └── Preparation 🔥 │ ├── Tips & Help │ ├── sorting the array reverse order in-built method.md │ ├── Reverse digit using For Loop.md │ ├── Prefix sum.java │ ├── math max method alternative Stream Array.md │ ├── arraylist add method features index and value both.md │ └── String has repeat method.md │ ├── HackerRank │ └── Java │ │ └── Java 1D Array.md │ └── LeetCode │ └── Stack │ └── Easy │ └── 1544. Make The String Great.md ├── CONTRIBUTING.md ├── 100 Days Of Code ├── Links │ └── Links.md ├── Leetcode │ ├── Look.md │ ├── Medium │ │ ├── 74. Search a 2D Matrix.md │ │ ├── 238. Product of Array Except Self.md │ │ └── 912. Sort an Array.md │ ├── Easy │ │ ├── 136. Single Number.md │ │ ├── 485. Max Consecutive Ones.md │ │ ├── 125. Valid Palindrome.md │ │ ├── 1539. Kth Missing Positive Number.md │ │ ├── 283. Move Zeroes.md │ │ └── 9. Palindrome Number.md │ ├── 268. Missing Number.md │ ├── 1. Two Sum.md │ ├── 137. Single Number II.md │ ├── 1823. Find the Winner of the Circular Game.md │ ├── 287. Find the Duplicate Number.md │ └── 136. Single Number.md ├── GFG │ └── 1. Largest Element in Array.md └── Neetcode 150 │ └── 1. Duplicate Integer.md └── .github ├── ISSUE_TEMPLATE ├── custom.md └── feature_request.md └── workflows └── youtube-workflow.yml /0001-two-sum/NOTES.md: -------------------------------------------------------------------------------- 1 | ​ -------------------------------------------------------------------------------- /src/Java/Random/Number Program/Natural: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Java/Random/Number Program/Number: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/readme.md: -------------------------------------------------------------------------------- 1 | paused. -------------------------------------------------------------------------------- /src/Java/LeetCode/Jai Shree Ganesh.txt: -------------------------------------------------------------------------------- 1 | hari om -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/searching using recursion .java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | feel free contribute on this repository. 2 | -------------------------------------------------------------------------------- /src/Java/Series/today/Array, String , Sorting/String Palindrome.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/SELF/week 9/External/HashMap/Easy/Character Frequencies.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /100 Days Of Code/Links/Links.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/two-sum/ 2 | -------------------------------------------------------------------------------- /src/SELF/week 9/External/SubArray/Medium/Maximum Contiguous Subarray Sum.java: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/Grind 169/link.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/list/?selectedList=ezjf98pm -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/Grind 75/link.md: -------------------------------------------------------------------------------- 1 | https://www.techinterviewhandbook.org/grind75 2 | 3 | -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/Blind 75 Must Do Leetcode/link.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/list/?selectedList=ezjjyvug -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/Leetcode/60 questions to solve/link.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/list/?selectedList=ezjbzfp7 -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/Grind 75/Blind 75 Must Do Leetcode/link.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/list/?selectedList=ezjjq9cm 2 | -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/Look.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/problems/group-anagrams/solutions/3687735/beats-100-c-java-python-beginner-friendly/ 2 | 3 | -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/GFG/Top 50 Array Coding Problems for Interviews/link.md: -------------------------------------------------------------------------------- 1 | ``https://www.geeksforgeeks.org/top-50-array-coding-problems-for-interviews/`` -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/GFG/Top 50 String Coding Problems for Interviews/link.md: -------------------------------------------------------------------------------- 1 | ``https://www.geeksforgeeks.org/top-50-string-coding-problems-for-interviews/`` -------------------------------------------------------------------------------- /src/Java/LeetCode/mahadev.txt: -------------------------------------------------------------------------------- 1 | Jai shree Ganesh 2 | Har Har mahadev 3 | har har mahadev 4 | jai shree ram 5 | jai bajarang bali 6 | jai hanuman 7 | jai shree ram 8 | -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/GFG/Practice for cracking any coding interview/link.md: -------------------------------------------------------------------------------- 1 | ``https://www.geeksforgeeks.org/practice-for-cracking-any-coding-interview/?ref=lbp`` -------------------------------------------------------------------------------- /src/Java/Data Structure/Tree/Tree/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Trees; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/14 Patterns to Ace Any Coding Interview Question/link.md: -------------------------------------------------------------------------------- 1 | https://hackernoon.com/14-patterns-to-ace-any-coding-interview-question-c5bb3357f6ed 2 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/08. LinkedList/README.md: -------------------------------------------------------------------------------- 1 | # [**First come here and Recall your LinkedList concepts then solve Qs**](../.././01.%20DataStructures/01.%20LinkList) 2 | 3 | -------------------------------------------------------------------------------- /src/SELF/week 1/Random/sum.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int a = 10, b=20, c=a+b; System.out.print(c); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /Interview Ready Solution/Preparation 🔥/Tips & Help/sorting the array reverse order in-built method.md: -------------------------------------------------------------------------------- 1 | ```java 2 | //Time: O(NlgN); Space: O(lgN) 3 | Arrays.sort(people, (a, b) -> b[0] - a[0]); 4 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/02. Matrix/08. Common elements in all rows/README.md: -------------------------------------------------------------------------------- 1 | # **[Common elements in all rows](https://www.geeksforgeeks.org/common-elements-in-all-rows-of-a-given-matrix/)** 2 | -------------------------------------------------------------------------------- /src/Theory/Interview Tricky Question/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.sourcePaths": [ 3 | "LinkedList", 4 | "Case&TypeConversion", 5 | "Arrays", 6 | "" 7 | ] 8 | } -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/GFG/Must Do Coding Questions for Companies like Amazon, Microsoft, Adobe, …/link.md: -------------------------------------------------------------------------------- 1 | ``https://www.geeksforgeeks.org/must-do-coding-questions-for-companies-like-amazon-microsoft-adobe/`` -------------------------------------------------------------------------------- /Interview Ready Solution/Grind/Leetcode/Comprehensive Data Structure and Algorithm Study Guide/Link.md: -------------------------------------------------------------------------------- 1 | https://leetcode.com/discuss/general-discussion/494279/comprehensive-data-structure-and-algorithm-study-guide 2 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/03. Strings/03. Print Duplicates/README.md: -------------------------------------------------------------------------------- 1 | # **[Print all the duplicates in the input string](https://www.geeksforgeeks.org/print-all-the-duplicates-in-the-input-string/)** 2 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/09. Trees/03. BinarySearchTrees/13. Merge 2 BSTs GQ/README.md: -------------------------------------------------------------------------------- 1 | # [**Merge Two Balanced Binary Search Trees**](https://www.geeksforgeeks.org/merge-two-balanced-binary-search-trees/) 2 | -------------------------------------------------------------------------------- /src/Theory/Interview Tricky Question/Case&TypeConversion/StringMethod.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/Theory/Interview Tricky Question/Case&TypeConversion/StringMethod.class -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/03. Strings/04. Check String Rotations/README.md: -------------------------------------------------------------------------------- 1 | # **[check if strings are rotations of each other or not](https://www.geeksforgeeks.org/a-program-to-check-if-strings-are-rotations-of-each-other/)** 2 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/03. Strings/05. valid shuffle string/README.md: -------------------------------------------------------------------------------- 1 | # **[Check if a string is a valid shuffle of two distinct strings](https://www.programiz.com/java-programming/examples/check-valid-shuffle-of-strings)** 2 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Basic Operation/3. Stack using Queue/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1 :** [Visualize here by codeWhoop](https://youtu.be/kKjYSBeDpFA) 2 | 3 | ### **Step 2:** [See my code here](./Stack_Queue.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/01. Arrays/03. Sorting/01. BubbleSort/README.md: -------------------------------------------------------------------------------- 1 | ![BSort](https://user-images.githubusercontent.com/71629248/120898477-a6019a80-c648-11eb-8297-aeaa6ccd078d.jpg) 2 | 3 | ## **[Video Reference](https://youtu.be/bBQkErahU9c)** 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/01. Arrays/03. Sorting/02. InsertionSort/README.md: -------------------------------------------------------------------------------- 1 | ![Isort](https://user-images.githubusercontent.com/71629248/120915812-7ba0f300-c6c3-11eb-9dc2-dfca36333645.jpg) 2 | # **[Video Reference](https://youtu.be/wWhAhp6PIuQ)** 3 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/06. Baseball Game #682/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Baseball Game #682](https://leetcode.com/problems/baseball-game/) 2 | 3 | #### **Solution Link:** [Baseball Game #682 solution](./Solution.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/04. Baseball Game #682/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Baseball Game #682](https://leetcode.com/problems/baseball-game/) 2 | 3 | #### **Solution Link:** [Baseball Game #682 solution](./Solution.java) 4 | -------------------------------------------------------------------------------- /src/Java/Random/Remove Duplicates from Sorted Array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeDuplicates(int[] nums) { 3 | int i = 0; 4 | for (int n : nums) 5 | if (i == 0 || n > nums[i-1]) 6 | nums[i++] = n; 7 | return i; 8 | } 9 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Random/table create .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int n = 2; 6 | for(int i=1; i<=10; i++){ 7 | System.out.println(i*2); 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/03. Queue using stacks/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1:** [Visualize Queue using stack here in 10min only](https://youtu.be/ma1S6vtkw9I) 2 | 3 | ### **Step 2:** [Try to understand my code here.](./Queue_Stack.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/01. Arrays/03. Sorting/03. SelectionSort/README.md: -------------------------------------------------------------------------------- 1 | ![Selection Sort](https://user-images.githubusercontent.com/71629248/121025520-dc632500-c7c2-11eb-875d-919cd0d413d9.jpg) 2 | 3 | ## **[Video Reference](https://youtu.be/B-nqY6IYqVw)** 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/01. Queue using array/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/01. Queue using array/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/04. Circular Queue using array/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1:** [Visualize Circular Queue using array ](https://youtu.be/KSvMGwc9dN8) 2 | 3 | ### **Step 2:** [Try to understand my code here.](./CircularQueue_Array.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/1. Singly-LinkList/InterviewBit Qs/12. Reverse LL-ii/Resources.md: -------------------------------------------------------------------------------- 1 | **Problem Link:** [Reverse LinkList ii- InterviewBit](https://www.interviewbit.com/problems/reverse-link-list-ii/) 2 | 3 | **Code Link:** [See my Code here](./solution.java) -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/3. Circular-LinkList/Resources.md: -------------------------------------------------------------------------------- 1 | **Step1 Tutorial Link:** [Circular LL playlist by Dinesh Varyani](https://youtube.com/playlist?list=PLGeDISzAH2BSoy_qPqzPVBVf28jrmYZq1) 2 | 3 | **Step2 Code Link:** [See my Code here](./CircularLL.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/01. Infix to Postfix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/01. Infix to Postfix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/02. Infix to Prefix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/02. Infix to Prefix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/03. Postfix to Infix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/03. Postfix to Infix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/04. Prefix to Infix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/04. Prefix to Infix/pseudocode.png -------------------------------------------------------------------------------- /src/SELF/week 6/Tree/HackerRank/Height of a Binary Tree.java: -------------------------------------------------------------------------------- 1 | https://www.hackerrank.com/challenges/tree-height-of-a-binary-tree/problem 2 | 3 | public static int height(Node root) { 4 | if(root==null) return -1; 5 | return 1+ Math.max(height(root.left),height(root.right)); 6 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/1. Singly-LinkList/InterviewBit Qs/03. Kth Node From Middle/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Problem Link** [Kth Node from Middle](https://www.interviewbit.com/problems/kth-node-from-middle/) 2 | 3 | ### **Solution:** [See my Code here](./solution.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/05. Postfix to Prefix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/05. Postfix to Prefix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/06. Prefix to Postfix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/06. Prefix to Postfix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/10. Make The String Great #1544/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Make The String Great #1544](https://leetcode.com/problems/make-the-string-great/) 2 | 3 | #### **Solution Link:** [Make The String Great #1544 solution](./Solution.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/1. Singly-LinkList/InterviewBit Qs/11. Rotate LL by K place/Resources.md: -------------------------------------------------------------------------------- 1 | **Problem Link:** [Rotate LinkList by k places- InterviewBit](https://www.interviewbit.com/problems/rotate-list/) 2 | 3 | **Code Link:** [See my Code here](./solution.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/2. Doubly-LinkList/Basic Operations/Resources.md: -------------------------------------------------------------------------------- 1 | **Step1 Tutorial Link:** [Doubly LL playlist by Dinesh Varyani](https://youtube.com/playlist?list=PLGeDISzAH2BQE20-hT461jmaeXFjdND7I) 2 | 3 | **Step2 Code Link:** [See my Code here](./DoublyLL.java) 4 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Basic Operation/2. Stack using LinkList/Resources.md: -------------------------------------------------------------------------------- 1 | **Step 1-Tutorial Link:** [Implementation of stack using LinkList by Dinesh Varyani](https://youtu.be/Us4N22SEbM0) 2 | 3 | **Step 2-Code Link:** [See my code here in java](./Stack_LinkList.java) 4 | -------------------------------------------------------------------------------- /src/Java/Data Structure/Tree/Node.java: -------------------------------------------------------------------------------- 1 | package com.company.Trees; 2 | 3 | public class Node { 4 | int data; 5 | Node left; 6 | Node right; 7 | 8 | public Node(int data){ 9 | this.data=data; 10 | this.left =null; 11 | this.right=null; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/SELF/week 1/square number get.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int n=25; 6 | for(int i=1;i bool: 4 | orig = x 5 | back_x = 0 6 | while x > 0: 7 | back_x = (back_x * 10) + (x % 10) 8 | x = x // 10 9 | return orig == back_x 10 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/2. Doubly-LinkList/Questions/1. Two Pair Sum/2 pair sum Q.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/01. DataStructures/01. LinkList/2. Doubly-LinkList/Questions/1. Two Pair Sum/2 pair sum Q.pdf -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/01. Infix to Postfix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/01. Infix to Postfix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/02. Infix to Prefix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/02. Infix to Prefix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/03. Postfix to Infix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/03. Postfix to Infix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/04. Prefix to Infix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/04. Prefix to Infix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/05. Postfix to Prefix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/05. Postfix to Prefix/pseudocode.png -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/06. Prefix to Postfix/pseudocode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anishkumar127/Data-Structures-and-Algorithms/HEAD/src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/06. Prefix to Postfix/pseudocode.png -------------------------------------------------------------------------------- /Interview Ready Solution/Preparation 🔥/Tips & Help/Reverse digit using For Loop.md: -------------------------------------------------------------------------------- 1 | ```java 2 | private static int reverse(int n) { 3 | int add = 0; 4 | for (int i = n; i != 0; i /= 10) { 5 | add = add * 10 + (i % 10); 6 | } 7 | return add; 8 | } 9 | 10 | ``` 11 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/06. DP/02. Qs/02. nPr/README.md: -------------------------------------------------------------------------------- 1 | # [**nPr**](https://www.geeksforgeeks.org/permutation-coefficient/) 2 | [**Video reference**](https://youtu.be/Ebj83h76VUU) 3 | ```java 4 | TC-O(N) SC-O(1) 5 | 6 | int p=1; 7 | for(int i=0; i bool: 4 | for num in matrix: 5 | for val in num: 6 | if val ==target: 7 | return True 8 | return False 9 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/01. Remove Outermost Parentheses #1021/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Remove Outermost Parentheses #1021](https://leetcode.com/problems/remove-outermost-parentheses/) 2 | 3 | #### **Solution Link:** [Remove Outermost Parentheses #1021 solution](./Solution.java) 4 | -------------------------------------------------------------------------------- /100 Days Of Code/GFG/1. Largest Element in Array.md: -------------------------------------------------------------------------------- 1 | ## me 2 | 3 | ```python 4 | class Solution: 5 | def largest(self, n : int, arr : List[int]) -> int: 6 | # code here 7 | max_el = -1 8 | for val in arr: 9 | max_el = max(max_el,val) 10 | return max_el 11 | 12 | 13 | ``` 14 | 15 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/02. Queue using linklist/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1:** [Visualize Queue using linklist here by Apna College in 6min only](https://youtu.be/Yi8Im4_eSQI) 2 | 3 | ### **Step 2:** [Recall your Linklist knowledge and try to understand my code here.](./Queue_Linklist.java) 4 | -------------------------------------------------------------------------------- /src/Java/GFG/WaveArray.java: -------------------------------------------------------------------------------- 1 | 2 | class Solution { 3 | public static void convertToWave(int n, int[] a) { 4 | 5 | for(int i=0; i2->3->4->5->6 15 | Output: 1->3->5 16 | */ -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/11. Backspace String Compare #844/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Backspace String Compare #844](https://leetcode.com/problems/backspace-string-compare/) 2 | 3 | #### **Solution Links:-** 4 | 5 | - [Backspace String Compare #844 Solution_self Optimized 🙈](./Solution_self.java) 6 | - [Backspace String Compare #844 Solution_editorial](./Editorial.java) 7 | -------------------------------------------------------------------------------- /Interview Ready Solution/Preparation 🔥/Tips & Help/math max method alternative Stream Array.md: -------------------------------------------------------------------------------- 1 | ```java 2 | // find min, max, sum etc value into stream array. and return it. 3 | // if not find then its return if not then its assign max value. 4 | // in min found case we need to min() method and Integer.MIN_VALUE; 5 | int max = Arrays.stream(candies).max().orElse(Integer.MAX_VALUE); 6 | 7 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/12. Daily Temperatures #739/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Problem Link:** 2 | 3 | - #### [Daily Temperatures #739](https://leetcode.com/problems/daily-temperatures/) 4 | 5 | ### **Solution Link:** 6 | 7 | - #### [Daily Temperatures #739 solution](./Solution.java) 8 | 9 | ### **Tutorial Link:** [Visualization by Alexander Le](https://youtu.be/WGm4Kj3lhRI) 10 | -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/SumOfDigit.java: -------------------------------------------------------------------------------- 1 | package Try; 2 | 3 | public class SumOfDigit { 4 | public static void main(String[] args) { 5 | int ans = digit(1342); 6 | System.out.print(ans); 7 | } 8 | private static int digit(int n){ 9 | 10 | // base case 11 | if(n==0){ 12 | return 0; 13 | } 14 | return (n%10) + digit(n/10) ; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/08. Backspace String Compare #844/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Backspace String Compare #844](https://leetcode.com/problems/backspace-string-compare/) 2 | 3 | #### **Solution Links:-** 4 | 5 | - [Backspace String Compare #844 Solution_self Optimized 🙈](./Solution_self.java) 6 | - [Backspace String Compare #844 Solution_editorial](./Editorial.java) 7 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/1. Singly-LinkList/InterviewBit Qs/08. Remove nth Node from List end GQ/Resources.md: -------------------------------------------------------------------------------- 1 | **Problem Link:** [Remove nth node from lis end- InterviewBit](https://www.interviewbit.com/problems/remove-nth-node-from-list-end/) 2 | 3 | **Tutorial Link:** [Remove nth node from lis end- takeUforward](https://youtu.be/Lhu3MsXZy-Q) 4 | 5 | **Code Link:** [See my Code here](./solution.java) -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/06. Dequeue using circular array/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1:** [Visualize Dequeue using circular array](https://www.studytonight.com/data-structures/double-ended-queue) 2 | 3 | ### **Step 2:** [Try to understand my code here.](./Dequeue_CircularArray.java) 4 | 5 | ### **Step 3:** [Learn about builtIn ArrayDequeue class in java](https://youtu.be/V_NVMqxcNaI) 6 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/16. Score of Parentheses #856/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Problem Link:** 2 | 3 | - #### [Score of Parentheses #856](https://leetcode.com/problems/score-of-parentheses/) 4 | 5 | ### **Solution Link:** 6 | 7 | - #### [Score of Parentheses #856 solution](./Solution.java) 8 | 9 | ### **Tutorial Link:** [Score of Parentheses by Nick White](https://youtu.be/jfmJusJ0qKM) 10 | -------------------------------------------------------------------------------- /src/Java/LeetCode/Find Pivot Index.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int pivotIndex(int[] nums) { 3 | int sum =0; // 28 4 | int ans =0; 5 | for(int n:nums){ 6 | sum+=n; 7 | } 8 | for(int i=0; i stack = new Stack<>(); 5 | 6 | for(char ch: s) stack.push(ch); 7 | 8 | for(int i=0; i=0; i--){ 7 | int temp = arr[i]; 8 | arr[i] = max; 9 | if(temp>max){ 10 | max = temp; 11 | } 12 | } 13 | return arr; 14 | } 15 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/17. Validate Stack Sequences #946/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Problem Link:** 2 | 3 | - #### [Validate Stack Sequences #946](https://leetcode.com/problems/validate-stack-sequences/) 4 | 5 | ### **Solution Link:** 6 | 7 | - #### [Validate Stack Sequences #946 solution](./Solution.java) 8 | 9 | ### **Tutorial Link:** [Validate Stack Sequences by AlgorithmMEasy](https://youtu.be/SeTsK_aNUWI) 10 | -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/print all occurance using recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // output 1 3 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {1,2,3,2,3,1}; 6 | int s = 2; 7 | output(arr,0,s); 8 | } 9 | private static void output(int arr[], int i, int s){ 10 | if(i==arr.length) return; 11 | if(arr[i]==s) System.out.print(i+" ") ; 12 | output(arr,i+1,s); 13 | } 14 | } -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/Easy/136. Single Number.md: -------------------------------------------------------------------------------- 1 | # HASHMAP 2 | 3 | 4 | # XOR 5 | 6 | 7 | ```python 8 | class Solution: 9 | 10 |     def singleNumber(self, nums: List[int]) -> int: 11 | 12 |         xor = 0 13 | 14 |         for val in nums: 15 | 16 |             xor = xor^val 17 | 18 |         return xor # we do xor duplicate remove and left the remaning which is unique. 19 | 20 |         # 1 ^ 1 = 0 , 1 ^ 1 ^ 2 = 2 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /Interview Ready Solution/Preparation 🔥/Tips & Help/String has repeat method.md: -------------------------------------------------------------------------------- 1 | 2 | ```java 3 | class Solution { 4 | 5 | void printTriangle(int n) { 6 | while(n>0){ 7 | String s ="* "; 8 | System.out.println(s.repeat(n)); 9 | n--; 10 | } 11 | } 12 | } 13 | ``` 14 | 15 | 16 | String st = "abc"; 17 | int count = 3; 18 | 19 | st.repeat(count); 20 | *it will repeat string 3 times* **abcabcabc** -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/01. Arrays/18. Best Time to Buy and Sell Stock/iii 123/README.md: -------------------------------------------------------------------------------- 1 | # **[123. Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/)** 2 | ![stock](https://user-images.githubusercontent.com/71629248/122765223-ee15f380-d2bd-11eb-874d-84f648632800.png) 3 | # **[Code Link](https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-stock-at-most-twice-set-2/)** 4 | -------------------------------------------------------------------------------- /src/Java/Random/Recursion/MIn elements in array.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int [] arr = {4,1,3,2,56}; 6 | int ans = code(arr,0); 7 | System.out.print(ans); 8 | } 9 | private static int code(int arr[], int i ){ 10 | if(i == arr.length-1) return arr[i]; 11 | 12 | int min = code(arr,i+1); 13 | return Math.min(arr[i],min); 14 | } 15 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/14. Validate Stack Sequences #946/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Problem Link:** 2 | 3 | - #### [Validate Stack Sequences #946](https://leetcode.com/problems/validate-stack-sequences/) 4 | 5 | ### **Solution Link:** 6 | 7 | - #### [Validate Stack Sequences #946 solution](./Solution.java) 8 | 9 | ### **Tutorial Link:** [Validate Stack Sequences by AlgorithmMEasy](https://youtu.be/SeTsK_aNUWI) 10 | -------------------------------------------------------------------------------- /src/Java/LeetCode/Array/Contains Duplicate (n^2).java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean containsDuplicate(int[] nums) { 3 | 4 | for(int i =0; i stack = new Stack<>(); 7 | 8 | for(char ch:s.toCharArray()) stack.push(ch); 9 | 10 | for(int i=0; i int: 5 | 6 |         maxi = 0 7 | 8 |         count = 0 9 | 10 |         for val in nums: 11 | 12 |             if val ==1: 13 | 14 |                 count +=1 15 | 16 |                 maxi = max(maxi,count) 17 | 18 |             else: 19 | 20 |                 count = 0 21 | 22 |         return maxi 23 | ``` -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/minimum elements in array using recursion .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // 1 3 | public class Main { 4 | public static void main(String[] args) { 5 | int [] arr = {4,1,3,2,56}; 6 | int ans = code(arr,0); 7 | System.out.print(ans); 8 | } 9 | private static int code(int arr[], int i ){ 10 | if(i == arr.length-1) return arr[i]; 11 | 12 | int min = code(arr,i+1); 13 | return Math.min(arr[i],min); 14 | } 15 | } -------------------------------------------------------------------------------- /src/SELF/week 6/Tree/Leetcode/bfs Kth Smallest Element in a BST.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int kthSmallest(TreeNode root, int k) { 3 | LinkedList stack = new LinkedList<>(); 4 | 5 | while (true) { 6 | while (root != null) { 7 | stack.push(root); 8 | root = root.left; 9 | } 10 | root = stack.pop(); 11 | if (--k == 0) return root.val; 12 | root = root.right; 13 | } 14 | } 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/268. Missing Number.md: -------------------------------------------------------------------------------- 1 | ## me 2 | 3 | ```python 4 | class Solution: 5 | 6 |     def missingNumber(self, nums: List[int]) -> int: 7 | 8 |         map = {} 9 | 10 |         for i in range(0, len(nums)): 11 | 12 |             map[nums[i]] = i 13 | 14 |         idx = 0 15 | 16 |         for idx in range(0, len(nums)): 17 | 18 |             if idx not in map: 19 | 20 |                 return idx 21 | 22 |         return idx + 1 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /src/JavaScript/LeetCode/Tree/Two Sum O(n^2).js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} target 4 | * @return {number[]} 5 | */ 6 | var twoSum = function(nums, target) { 7 | let n = nums.length; 8 | for(let i=0; i 10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/04. Prefix to Infix/Resources.md: -------------------------------------------------------------------------------- 1 | **NOTE:** [You should know Step 3 from here.](../01.%20Infix%20to%20Postfix/Resources.md) 2 | 3 | ### **Step 1:** [Understand the working of pseudocode](https://youtu.be/sevlImM3Onc) 4 | 5 | ![](./pseudocode.png) 6 | 7 | ### **Step 2:** [See my code here in java to convert prefix to infix using stack.](./PrefixInfix.java) 8 | 9 |
10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/SELF/week 1/Random/swap two number and print.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | public class Main 6 | { 7 | public static void main (String[] args) throws java.lang.Exception 8 | { 9 | //your code here 10 | Scanner sc = new Scanner(System.in); 11 | int a = sc.nextInt(); 12 | int b = sc.nextInt(); 13 | 14 | int temp = a; 15 | a = b; 16 | b = temp; 17 | System.out.print(a+" "+b); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/SELF/week 1/increment array program .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // Output: 3 | 4 | // 1 1 1 1 1 5 | public class Main { 6 | public static void main(String[] args) { 7 | int [] arr = new int [5]; 8 | increment(arr); 9 | for(int i :arr){ 10 | System.out.print(i+" "); 11 | } 12 | } 13 | private static void increment(int []arr ){ 14 | 15 | for(int i=0; i=0; i--){ 5 | if(s.charAt(i)=='1'){ 6 | return i; 7 | } 8 | } 9 | return -1; 10 | } 11 | } 12 | 13 | 14 | 15 | int i,index=-1; 16 | for(i=0; i 10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/04. Prefix to Infix/Resources.md: -------------------------------------------------------------------------------- 1 | **NOTE:** [You should know Step 3 from here.](../01.%20Infix%20to%20Postfix/Resources.md) 2 | 3 | ### **Step 1:** [Understand the working of pseudocode](https://youtu.be/sevlImM3Onc) 4 | 5 | ![](./pseudocode.png) 6 | 7 | ### **Step 2:** [See my code here in java to convert prefix to infix using stack.](./PrefixInfix.java) 8 | 9 |
10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/Java/Random/Recursion/first occurance of elements in array using recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {1,2,3,2,3,1}; 6 | int s = 2; 7 | int ans = output(arr,0,s); 8 | System.out.print(ans); 9 | 10 | } 11 | private static int output(int arr[], int i, int s){ 12 | 13 | if(i==arr.length) return -1; 14 | if(arr[i]==s) return i; 15 | return output(arr,i+1,s); 16 | } 17 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Day in Month.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | if(n==2){ 8 | System.out.print("28"); 9 | return; 10 | } 11 | if(n==1|| n==3|| n==5|| n==7|| n == 8|| n ==10|| n==12){ 12 | System.out.print("31"); 13 | }else{ 14 | System.out.print("30"); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0001-two-sum/0001-two-sum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | HashMapmap = new HashMap<>(); 4 | 5 | for(int i=0; i 10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/Java/Random/Recursion/searching in array.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {1,2,3,4,5,6,7}; 6 | int search = 4; 7 | boolean ans = output(arr,0,search); 8 | System.out.print(ans); 9 | } 10 | public static boolean output(int arr[] , int i, int s ){ 11 | 12 | if(i==arr.length) return false; 13 | if(arr[i] == s) return true; 14 | 15 | return output(arr,i+1 , s); 16 | 17 | } 18 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Random/switch case conditional problem .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | public class Main 6 | { 7 | public static void main (String[] args) throws java.lang.Exception 8 | { 9 | 10 | Scanner sc = new Scanner(System.in); 11 | int n = sc.nextInt(); 12 | switch(n){ 13 | case 1: 14 | System.out.println("you entered less"); 15 | break; 16 | default: 17 | System.out.println("you entered more"); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/find 1st occurrences of elements in array using recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // output 1 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {1,2,3,2,3,1}; 6 | int s = 2; 7 | int ans = output(arr,0,s); 8 | System.out.print(ans); 9 | 10 | } 11 | private static int output(int arr[], int i, int s){ 12 | 13 | if(i==arr.length) return -1; 14 | if(arr[i]==s) return i; 15 | return output(arr,i+1,s); 16 | } 17 | } -------------------------------------------------------------------------------- /src/SELF/week 1/print all digit of a number on different lines.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | input 108 4 | output: 5 | 8 6 | 0 7 | 1 8 | 9 | 10 | \*/ 11 | public class Main { 12 | public static void main(String[] args) { 13 | int n = 108; 14 | int m = n; 15 | while(n!=0){ 16 | int d = n%10; 17 | System.out.println(d); 18 | n = n /10; 19 | } 20 | // System.out.print(m); // 108 21 | // System.out.println(); 22 | // System.out.print(n); // 0 23 | } 24 | } -------------------------------------------------------------------------------- /src/SELF/week 6/Two Sum one pass hashmap.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | HashMapmap = new HashMap<>(); 4 | 5 | for(int i=0; i List[int]: 7 | 8 |         map ={} 9 | 10 |         for i in range(len(nums)): 11 | 12 |             seen = target - nums[i] 13 | 14 |             print(seen) 15 | 16 |             if seen in map: 17 | 18 |                 return [map[seen],i] 19 | 20 |             else: 21 | 22 |                 map[nums[i]] = i 23 | 24 |         return [-1,-1] 25 | ``` 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/Infix Prefix Postfix/06. Prefix to Postfix/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1:** [Postfix to Prefix and viceversa **manual conversion**.](https://youtu.be/tuRwmc6Jo1U?t=1097) 2 | 3 | ### **Step 2:** [Visualize pseudocode to convert prefix to postfix.](https://youtu.be/CV7jwxSz8cg) 4 | 5 | ![](./pseudocode.png) 6 | 7 | ### **Step 3:** [See my code here in java to convert prefix to postfix using stack.](./PrefixPostfix.java) 8 | 9 |
10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/08. LinkedList/10. Move LastE to first in LL/README.md: -------------------------------------------------------------------------------- 1 | # [**Move last element to front of a given Linked List**](https://www.geeksforgeeks.org/move-last-element-to-front-of-a-given-linked-list/) 2 | ```java 3 | ListNode modify(ListNode head){ 4 | ListNode seclast=head; 5 | while(seclast.next.next!=null){ 6 | seclast=seclast.next; 7 | } 8 | ListNode last=seclast.next; 9 | 10 | last.next=head; 11 | head=last; 12 | seclast.next=null; 13 | } 14 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/18. Infix Prefix Postfix/05. Postfix to Prefix/Resources.md: -------------------------------------------------------------------------------- 1 | ### **Step 1:** [Postfix to Prefix and viceversa **manual conversion**.](https://youtu.be/tuRwmc6Jo1U) 2 | 3 | ### **Step 2:** [Visualize pseudocode to convert postfix to prefix.](https://youtu.be/4GTqpV_dqKY) 4 | 5 | ![](./pseudocode.png) 6 | 7 | ### **Step 3:** [See my code here in java to convert postfix to prefix using stack.](./PostfixPrefix.java) 8 | 9 |
10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/ReverseDigit Recursion.java: -------------------------------------------------------------------------------- 1 | package Try; 2 | 3 | public class ReverseDigit1 { 4 | static int sum = 0; 5 | public static void main(String[] args) { 6 | reverseDigit1(2431); 7 | System.out.print(sum); 8 | } 9 | 10 | private static void reverseDigit1(int n){ 11 | // base case 12 | if(n==0){ 13 | return; 14 | } 15 | int rem = n%10; 16 | sum = sum *10 + rem; 17 | reverseDigit1(n/10); 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/SELF/week 6/Leetcode/Binary Search/Search Insert Position.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int searchInsert(int[] nums, int target) { 3 | int s=0; 4 | int e =nums.length-1; 5 | while(s<=e){ 6 | int mid = s+(e-s)/2; 7 | if(nums[mid]==target){ 8 | return mid; 9 | }else if(nums[mid]>target){ 10 | e = mid-1; 11 | }else{ 12 | s = mid+1; 13 | } 14 | } 15 | return s; 16 | } 17 | } -------------------------------------------------------------------------------- /src/Java/Random/Number Program/Palindrome Number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // 121 yes 949943 no . 3 | public class Main { 4 | public static void main(String[] args) { 5 | int n = 121; 6 | int m = n; 7 | int sum =0; 8 | while(n!=0){ 9 | int d = n % 10; 10 | sum = sum* 10 + d; 11 | n = n/10; 12 | } 13 | if(sum == m ) 14 | System.out.println("yes"); 15 | else 16 | System.out.println("no"); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Java/Series/Function/Two Number Sum Using Function.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // using easy two number sum. with function. 3 | public class Main { 4 | public static int sum(int one, int two){ 5 | int s = 0; 6 | s = one + two; 7 | return s; 8 | } 9 | public static void main(String[] args) { 10 | Scanner sc=new Scanner(System.in); 11 | int one = sc.nextInt(); 12 | int two = sc.nextInt(); 13 | int data =sum(one,two); 14 | System.out.println(data); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Java/Series/Number Program/Palindrome Number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // 121 yes 949943 no . 3 | public class Main { 4 | public static void main(String[] args) { 5 | int n = 121; 6 | int m = n; 7 | int sum =0; 8 | while(n!=0){ 9 | int d = n % 10; 10 | sum = sum* 10 + d; 11 | n = n/10; 12 | } 13 | if(sum == m ) 14 | System.out.println("yes"); 15 | else 16 | System.out.println("no"); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Java/Series/String/find frequency of chracter in String.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // find frequency of character x in the String. 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc=new Scanner(System.in); 6 | String name = sc.nextLine(); 7 | char c = sc.next().charAt(0); 8 | int count =0; 9 | for(int i=0; i 4 +2 = 6. 17 | System.out.println(count); // 2 18 | int ans = sum/count; // 6 /2 = 6. 19 | System.out.print(ans); 20 | } 21 | } -------------------------------------------------------------------------------- /src/SELF/week 6/Kadane Algo/Leetcode/Maximum Subarray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxSubArray(int[] nums) { 3 | int n = nums.length; 4 | int sum =0; 5 | int max=Integer.MIN_VALUE; // add minimum value. 6 | for(int i=0; i int: 7 | 8 |         freq_map = {} 9 | 10 |         for val in nums: 11 | 12 |             if val in freq_map: 13 | 14 |                 freq_map[val]+=1 15 | 16 |             else: 17 | 18 |                 freq_map[val]=1 19 | 20 |         for key,val in freq_map.items(): 21 | 22 |             if val ==1: 23 | 24 |                 return key 25 | 26 |         return -1 27 | ``` -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/Easy/125. Valid Palindrome.md: -------------------------------------------------------------------------------- 1 | ```python 2 | class Solution: 3 | def isPalindrome(self, s: str) -> bool: 4 | if s == " ": 5 | return True 6 | low = 0 7 | item = re.sub(r'[^a-zA-Z0-9]', '', s).lower() 8 | high = len(item)-1 9 | print(item) 10 | while low < high: 11 | if item[low] == item[high]: 12 | low+=1 13 | high-=1 14 | else: 15 | return False 16 | return True 17 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/17. Validate Stack Sequences #946/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean validateStackSequences(int[] pushed, int[] popped) { 3 | Stack st=new Stack(); 4 | int j=0; 5 | for(int pu:pushed){ 6 | st.push(pu); 7 | while(!st.isEmpty() && j 10 |

Thank You

11 | -------------------------------------------------------------------------------- /src/Java/Random/Number Program/Natural Number Sum.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int sum =0; 6 | 7 | for(int i=0; i<=10; i++){ 8 | sum+=i; 9 | } 10 | System.out.print(sum); 11 | 12 | // while loop. 13 | 14 | int i=0; 15 | int sum=0; 16 | while(i<=10){ 17 | sum = sum+i; 18 | i++; 19 | } 20 | System.out.print(sum); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Java/Series/my practice/Find String Longest name.java: -------------------------------------------------------------------------------- 1 | /* 2 | Input: 3 | N = 5 4 | names[] = { "Geek", "Geeks", "Geeksfor","GeeksforGeek", "GeeksforGeeks" }; 5 | Output: 6 | GeeksforGeeks 7 | */ 8 | // return also min and check it. 9 | 10 | class GFG { 11 | String longest(String names[], int n) { 12 | String max = names[0]; 13 | for(int i=1; imax.length()){ 15 | max= names[i]; 16 | } 17 | } 18 | return max; 19 | } 20 | } -------------------------------------------------------------------------------- /src/SELF/week 1/N power 2 .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | STDIN 4 | 3 2 5 5 | 6 | Output: 7 | 8 | 3 6 12 24 48 9 | */ 10 | public class Main { 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | int a = sc.nextInt(); 14 | int r = sc.nextInt(); 15 | int n = sc.nextInt(); 16 | int curr_term; 17 | 18 | for (int i = 0; i < n; i++) { 19 | curr_term = a * (int)Math.pow(r, i); 20 | System.out.print(curr_term + " "); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Java/Random/Recursion/PrintArrayUsingRecursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {10,20,30,40,50,60,70}; 6 | int n = arr.length; 7 | output(arr,0,n-1); 8 | } 9 | public static int output(int[] arr,int i, int n ){ 10 | 11 | // int i =0; 12 | 13 | if(i>n){ 14 | return 0 ; 15 | } 16 | 17 | System.out.print(arr[i]+" "); 18 | int ans = output(arr, i+1,n); 19 | return ans; 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/1823. Find the Winner of the Circular Game.md: -------------------------------------------------------------------------------- 1 | 2 | ## me 3 | 4 | ```python 5 | class Solution: 6 | 7 |     def findTheWinner(self, n: int, k: int) -> int: 8 | 9 |         que = Deque() 10 | 11 | 12 | 13 |         for i in range(1,n+1): 14 | 15 |             que.append(i) 16 | 17 | 18 | 19 |         while len(que) > 1: 20 | 21 |             for i in range(1,k): 22 | 23 |                 que.append(que.popleft()) 24 | 25 |             que.popleft() 26 | 27 |         return que[0] 28 | ``` 29 | 30 | 31 | -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/Medium/238. Product of Array Except Self.md: -------------------------------------------------------------------------------- 1 | ## TLE Brute force 2 | 3 | 4 | ```python 5 | class Solution: 6 | 7 |     def productExceptSelf(self, nums: List[int]) -> List[int]: 8 | 9 |         ans = [] 10 | 11 |         for i in range(0, len(nums)): 12 | 13 |             temp = 1 14 | 15 |             for j in range(0 , len(nums)): 16 | 17 |                 if i != j : 18 | 19 |                     temp = temp* nums[j] 20 | 21 |             ans.append(temp) 22 | 23 |         return ans 24 | ``` 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/14. Validate Stack Sequences #946/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean validateStackSequences(int[] pushed, int[] popped) { 3 | Stack st=new Stack(); 4 | int j=0; 5 | for(int pu:pushed){ 6 | st.push(pu); 7 | while(!st.isEmpty() && j int: 6 | 7 |         freq_map = {} 8 | 9 |         for val in nums: 10 | 11 |             if val in freq_map: 12 | 13 |                 freq_map[val]+=1 14 | 15 |             else: 16 | 17 |                 freq_map[val]=1 18 | 19 |         for key,val in freq_map.items(): 20 | 21 |             if val>1 : 22 | 23 |                 return key 24 | 25 |         return -1 26 | ``` 27 | 28 | -------------------------------------------------------------------------------- /src/Java/Series/Sorting/InsertionSort.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int [] a={5,1,6,2,4,3}; 6 | int temp ,j; 7 | for(int i=1; i0 && a[j-1] > temp){ 11 | a[j] = a[j-1]; 12 | j=j-1; 13 | } 14 | a[j]=temp; 15 | } 16 | for(int k=0; k int: 7 | 8 |         frequency_map = {} 9 | 10 |         for val in nums: 11 | 12 |             if val in frequency_map: 13 | 14 |                 frequency_map[val]+=1 15 | 16 |             else: 17 | 18 |                 frequency_map[val] = 1 19 | 20 |         for key, val in frequency_map.items(): 21 | 22 |             if val ==1 : 23 | 24 |              return key 25 | 26 |         return -1 27 | ``` -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/Easy/1539. Kth Missing Positive Number.md: -------------------------------------------------------------------------------- 1 | 2 | ```python 3 | class Solution: 4 | 5 |     def findKthPositive(self, arr: List[int], k: int) -> int: 6 | 7 |         hashmap = {} 8 | 9 |         for i in range(0, len(arr)): 10 | 11 |             hashmap[arr[i]] = hashmap.get(arr[i], 0) + 1 12 | 13 |         for i in range(1, (arr[-1] + k) + 1): 14 | 15 |             if not hashmap.get(i): 16 | 17 |                 k -= 1 18 | 19 |                 if k == 0: 20 | 21 |                     return i 22 | 23 |         return k 24 | ``` -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/n%10 result.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // output 10 20 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {1,5,10,20,7}; 6 | 7 | output(arr,0); 8 | } 9 | private static void output(int arr[], int i){ 10 | 11 | // base case : 12 | if(i== arr.length) return ; 13 | 14 | // work. 15 | if(arr[i]%10==0){ 16 | System.out.print(arr[i]+" "); 17 | } 18 | 19 | // faith 20 | output(arr,i+1); 21 | 22 | 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/13. Score of Parentheses #856/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int scoreOfParentheses(String S) { 3 | Stack st=new Stack(); 4 | int score=0; 5 | for(char c: S.toCharArray()){ 6 | 7 | if(c=='('){ 8 | st.push(score); 9 | score=0; 10 | } 11 | else{ 12 | score=st.pop()+Math.max(2*score,1); 13 | } 14 | } 15 | return score; 16 | } 17 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/16. Score of Parentheses #856/Solution.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int scoreOfParentheses(String S) { 3 | Stack st=new Stack(); 4 | int score=0; 5 | for(char c: S.toCharArray()){ 6 | 7 | if(c=='('){ 8 | st.push(score); // save 9 | score=0; 10 | } 11 | else{ 12 | score=st.pop()+Math.max(2*score,1); 13 | } 14 | } 15 | return score; 16 | } 17 | } -------------------------------------------------------------------------------- /src/Java/Series/my practice/Find min & max Array using while loop.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[ ] = {5, 3, 1, 6, 9}; 6 | int n = arr.length; 7 | int j =n-1; 8 | int min = arr[0]; 9 | int max = arr[0]; 10 | while(j>0){ 11 | if(arr[j]>max){ 12 | max=arr[j]; 13 | } 14 | if(arr[j]n){ 14 | return 0 ; 15 | } 16 | 17 | System.out.print(arr[i]+" "); 18 | int ans = output(arr, i+1,n); 19 | return ans; 20 | 21 | } 22 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/sum until value less then single digit .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // input 123 3 | // output 6 4 | public class Main { 5 | public static void main(String[] args) { 6 | int n = 123; 7 | int ans = output(n); 8 | System.out.print(ans); 9 | } 10 | private static int output(int n){ 11 | if(n<10){ 12 | return n; 13 | } 14 | int sum =0; // 6 15 | while(n>0){ 16 | int rem = n%10; 17 | sum = sum+ rem; 18 | n = n/10; 19 | 20 | } 21 | return output(sum); 22 | } 23 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/11. Backspace String Compare #844/Editorial.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean backspaceCompare(String S, String T) { 3 | return build(S).equals(build(T)); 4 | } 5 | 6 | public String build(String S) { 7 | Stack ans = new Stack(); 8 | for (char c: S.toCharArray()) { 9 | if (c != '#') 10 | ans.push(c); 11 | else if (!ans.empty()) 12 | ans.pop(); 13 | } 14 | return String.valueOf(ans); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Java/Series/my practice/Find min & max while Loop new Way.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[ ] = {5, 3, 1, 6, 9}; 6 | int n = arr.length; 7 | int ans = 0; 8 | int i = 0; 9 | int j = n-1; 10 | while(iarr[i]){ 12 | j--; 13 | }else{ 14 | i++; 15 | } 16 | } 17 | ans = arr[i]; 18 | System.out.print(ans); 19 | } 20 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/Recursive sum until single degit.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int n = 12345; 6 | int ans = output(n); 7 | System.out.print(ans); 8 | } 9 | private static int output(int n ){ 10 | 11 | if(n<10){ 12 | return n ; 13 | } 14 | int sum =0; 15 | while(n>0){ 16 | int rem = n%10; 17 | sum = sum+ rem; 18 | n = n/10; 19 | 20 | } 21 | 22 | return output(sum); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Reverse Digit.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | // input 12345 5 | // output 54321 6 | public class Main 7 | { 8 | public static void main (String[] args) throws java.lang.Exception 9 | { 10 | //your code here 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | int x = n; 14 | int r =0; 15 | int sum =0; 16 | while(x>0){ 17 | int t = x%10; 18 | sum = (sum*10)+t; 19 | x = x/10; 20 | } 21 | System.out.print(sum); 22 | } 23 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/08. Backspace String Compare #844/Editorial.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean backspaceCompare(String S, String T) { 3 | return build(S).equals(build(T)); 4 | } 5 | 6 | public String build(String S) { 7 | Stack ans = new Stack(); 8 | for (char c: S.toCharArray()) { 9 | if (c != '#') 10 | ans.push(c); 11 | else if (!ans.empty()) 12 | ans.pop(); 13 | } 14 | return String.valueOf(ans); 15 | } 16 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/11. Minimum Add to Make Parentheses Valid #921/Resources.md: -------------------------------------------------------------------------------- 1 | #### **Problem Link:** [Minimum Add to Make Parentheses Valid #921](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) 2 | 3 | #### **Solution Link:** [Minimum Add to Make Parentheses Valid #921 solution](./Solution.java) 4 | 5 | **NOTE :** Before this [Do solve Q9(#20).](https://github.com/heyimanish/DataStructures-And-Algorithms/blob/5a3fb0ea815aefe7e8ced7842a7b3de8e089e07d/02.%20Stack/LeetCode%20Qs/09.%20Valid%20Parentheses%20%2320/Resources.md) 6 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/07. Searching & Sorting/19. Missing Number in AP/README.md: -------------------------------------------------------------------------------- 1 | # [**Arithmetic Number**](https://practice.geeksforgeeks.org/problems/arithmetic-number2815/1#) 2 | 3 | ## Thought Process :- 4 | ## An=A1+(n-1)d 5 | ```java 6 | class Solution{ 7 | static int inSequence(int A, int B, int C){ 8 | // code here 9 | if(C==0){ 10 | if(A==B) return 1; else return 0; 11 | } 12 | if((B-A)/C<0) return 0; 13 | if((B-A) % C == 0) return 1; 14 | return 0; 15 | } 16 | } 17 | ``` -------------------------------------------------------------------------------- /src/Java/Series/String/Duplicate Character 2nd way.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | input:- mynameisanish 4 | output:- mnais 5 | 6 | */ 7 | public class Main { 8 | public static void main(String[] args) { 9 | String name = "mynameisanish"; 10 | char chArr[]= name.toCharArray(); 11 | for(int i=0; i None: 5 | 6 |         """ 7 | 8 |         Do not return anything, modify nums in-place instead. 9 | 10 |         """ 11 | 12 |         idx = 0 13 | 14 |         for i in range(0, len(nums)): 15 | 16 |             if nums[i] != 0: 17 | 18 |                 nums[idx] = nums[i] 19 | 20 |                 idx += 1 21 | 22 | 23 | 24 |         while idx < len(nums): 25 | 26 |             nums[idx] = 0 27 | 28 |             idx += 1 29 | ``` 30 | 31 | -------------------------------------------------------------------------------- /src/Java/GFG/Find n-th term of series 1, 3, 6, 10, 15, 21.java: -------------------------------------------------------------------------------- 1 | //Question Link: https://practice.geeksforgeeks.org/problems/find-n-th-term-of-series-1-3-6-10-15-215506/1 2 | class Solution { 3 | 4 | //O(N) Solution 5 | static int findNthTerm(int N) { 6 | int sum = 0; 7 | for(int i = 0; i<=N; i++) { 8 | sum += i; 9 | } 10 | return sum; 11 | } 12 | 13 | //O(1) -> Simple Mathematical formula to calculate sum of first N natural Numbers 14 | static int findNthTerm(int N) { 15 | return (N*(N+1))>>1; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Java/Random/Geometric Series sum.java: -------------------------------------------------------------------------------- 1 | 5:07 PM 6/23/2022 2 | import java.util.*; 3 | /*\ 4 | Geometric Series sum 5 | 2-6+18-54.....n 6 | input: 7 | 1 out 2 8 | 2 output -4 9 | 10 | */ 11 | public class Main { 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | int sum =0; 15 | int n = sc.nextInt(); 16 | for(int i=1, k=2; i<=n; i++, k*=3){ 17 | if(i%2==0){ 18 | sum = sum-k; 19 | }else{ 20 | sum = sum+k; 21 | } 22 | 23 | } 24 | System.out.print(sum); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Java/GFG/Second Largest.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int printSecondLargestNumber(int arr[], int n) { 3 | if (n < 2) { 4 | return -1; 5 | } 6 | int max = 0; 7 | int sm = 0; 8 | for (int i = 0; i < n; i++) { 9 | if (arr[i] > max) { 10 | sm = max; 11 | max = arr[i]; 12 | } else if (arr[i] > sm && arr[i] != max) { 13 | sm = arr[i]; 14 | } 15 | } 16 | if (sm == 0) { 17 | return -1; 18 | } 19 | return sm; 20 | } 21 | 22 | //O(N*N) 23 | int printSecondLargestNumber2(int arr[], int n) { 24 | Arrays.sort(arr); 25 | return arr[1]; 26 | } 27 | } -------------------------------------------------------------------------------- /src/Java/HackerRank/Mini-Max Sum.md: -------------------------------------------------------------------------------- 1 | ``https://www.hackerrank.com/challenges/three-month-preparation-kit-mini-max-sum/problem`` 2 | 3 | ``` 4 | public static void miniMaxSum(List arr) { 5 | long maxSum=Integer.MIN_VALUE; 6 | long minSum=Integer.MAX_VALUE; 7 | long sum =0; 8 | for(int i=0; i0){ 12 | r= n%10; 13 | s = (s*10)+r; 14 | n = n/10; 15 | } 16 | if(c==s){ 17 | System.out.print("YES"); 18 | }else{ 19 | System.out.print("NO"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Java/Series/String/Find Index of Character X In The Given String.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // find Index of character x in the given String. 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | // String name = "mahadev"; 7 | String name = sc.nextLine(); 8 | char k = sc.next().charAt(0); 9 | for(int i=0; i=end) return true; 14 | 15 | // work 16 | if(arr[start]!=arr[end]) return false; 17 | 18 | // faith 19 | else return output(arr,start+1,end-1); 20 | 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/09. Crawler Log Folder #1598/Solution_stack.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minOperations(String[] logs) { 3 | Stack st=new Stack(); 4 | 5 | for(String log:logs){ 6 | if(log.equals("../") && st.isEmpty()) 7 | continue; 8 | else if(log.equals("../") ) 9 | st.pop(); 10 | else if(log.equals("./")) 11 | continue; 12 | else 13 | st.push(1); 14 | } 15 | 16 | return st.size(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/Java/Random/Factor Program/Deficient Number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | Deficient numbers occur more frequently than abundant numbers. In other words, 4 | the sum of the proper divisors of most numbers is less than the numbers 5 | themselves. 6 | 21 yes expml = 21 , 1,3,7 =11<21; 7 | 6 no. 8 | */ 9 | public class Main { 10 | public static void main(String[] args) { 11 | int n = 6; 12 | int sum =0; 13 | for(int i=1; i st=new Stack(); 4 | 5 | for(String log:logs){ 6 | if(log.equals("../") && st.isEmpty()) 7 | continue; 8 | else if(log.equals("../") ) 9 | st.pop(); 10 | else if(log.equals("./")) 11 | continue; 12 | else 13 | st.push(1); 14 | } 15 | 16 | return st.size(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/01. Arrays/01. Reverse Array/README.md: -------------------------------------------------------------------------------- 1 | ![reverse Array](https://user-images.githubusercontent.com/71629248/120749193-bb2fd980-c521-11eb-9b2b-c6635f5568a7.jpg) 2 | ## Reverse Array using recurssion 3 | ```java 4 | public static void main(String[] args) { 5 | int arr[]= {1,3,5,6,7,12,15}; 6 | int n=arr.length; 7 | reverseArr(arr,0,n-1); 8 | System.out.println(Arrays.toString(arr)); 9 | } 10 | static void reverseArr(int arr[],int s,int e) { 11 | if(s>=e) return; 12 | int temp=arr[s]; 13 | arr[s]=arr[e]; 14 | arr[e]=temp; 15 | reverseArr(arr,++s,--e); 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/n number sum recursive.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | 6 | int ans = Print(5); 7 | System.out.print(ans); 8 | } 9 | public static int Print(int n){ 10 | // base case 11 | // if(n==0) return 1; // output : 16; 12 | // if(n==1) return 0; // output : 14 ; 13 | // if(n==1) return 1; // output : 15; 14 | if(n==0) return 0; // output : 15; 15 | // faith / smaller subproblme 16 | int fait = Print(n-1); 17 | //work 18 | int ans = n + fait; 19 | 20 | return ans ; 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/SELF/week 1/string high ascii value .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // Output: 3 | 4 | // s 5 | // B 6 | public class Main { 7 | public static void main(String[] args) { 8 | String name = "anishBishnoi"; 9 | char max ='A'; 10 | for(int i=0; imax){ 12 | max = name.charAt(i); 13 | } 14 | } 15 | System.out.println(max); 16 | 17 | char min ='Z'; 18 | for(int i=0; i bool: 7 | 8 |         return str(x) == str(x)[::-1] # reverse using slice method 9 | ``` 10 | 11 | 12 | ```python 13 | class Solution: 14 | 15 |     def isPalindrome(self, x: int) -> bool: 16 | 17 |         temp = x 18 | 19 |         reversed_el = 0 20 | 21 |         while x > 0: 22 | 23 |             rem = int(x % 10) 24 | 25 |             reversed_el = (reversed_el * 10) + rem 26 | 27 |             x = int(x / 10) 28 | 29 |         return temp == reversed_el 30 | ``` 31 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/09. Crawler Log Folder #1598/Solution_optimised.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minOperations(String[] logs) { 3 | int depth = 0; 4 | for (String log : logs) { 5 | if (log.equals("./")) 6 | continue; 7 | else if (log.equals("../")) { 8 | depth--; 9 | if (depth < 0) 10 | depth = 0; 11 | } 12 | else 13 | depth++; 14 | } 15 | return depth; 16 | } 17 | } -------------------------------------------------------------------------------- /src/Java/Series/today/Array, String , Sorting/Check Number Palindrome or not.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // number palindrome or not. 3 | // 12121 . 121 . yes , 1234 no. 4 | public class Main { 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int n = sc.nextInt(); 8 | int c= n; 9 | int s=0; 10 | int r=0; 11 | while(n>0){ 12 | r= n%10; 13 | s = (s*10)+r; 14 | n = n/10; 15 | } 16 | if(c==s){ 17 | System.out.print("YES"); 18 | }else{ 19 | System.out.print("NO"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/palindrome array using recursion .java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // output true. 3 | public class Main { 4 | public static void main(String[] args) { 5 | int [] arr = {1,2,3,4,4,3,2,1}; 6 | boolean ans = output(arr,0,arr.length-1); 7 | System.out.print(ans); 8 | 9 | } 10 | private static boolean output(int arr[], int start , int end){ 11 | 12 | // base case 13 | if(start>=end) return true; 14 | 15 | // work 16 | if(arr[start]!=arr[end]) return false; 17 | 18 | // faith 19 | else return output(arr,start+1,end-1); 20 | 21 | 22 | } 23 | } -------------------------------------------------------------------------------- /src/SELF/week 1/Sum even number and count even number then sum both.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | // input 1 4 2 5 4 | // even 4 2 5 | // sum 6 6 | // 2 count then 6 + 2 = 8 7 | public class Main { 8 | public static void main(String[] args) { 9 | 10 | int arr[] = {1, 4 ,2 ,5}; 11 | int sum =0; 12 | int count = 0; 13 | for(int i=0; i ar) { 5 | // Write your code here 6 | int sum =0; 7 | for(int i=0; in) 20 | System.out.println("Yes"); 21 | else 22 | System.out.println("No"); 23 | } 24 | } -------------------------------------------------------------------------------- /src/Java/Series/Factor Program/Abundant Number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | an imperfect number that is less than the sum of all its divisors (as 12) 4 | 5 | 18 is abundant because the sum of its proper divisors ( 1 + 2 + 3 + 6 + 9 ) 6 | (1+2+3+6+9) (1+2+3+6+9) is greater than itself. 7 | 8 | 12 Yes. 9 | 15 No. 10 | */ 11 | public class Main { 12 | public static void main(String[] args) { 13 | int sum =0; 14 | int n = 15; 15 | for(int i=1; in) 20 | System.out.println("Yes"); 21 | else 22 | System.out.println("No"); 23 | } 24 | } -------------------------------------------------------------------------------- /100 Days Of Code/Leetcode/Medium/912. Sort an Array.md: -------------------------------------------------------------------------------- 1 | ```python 2 | class Solution: 3 | 4 |     def sortArray(self, nums: List[int]) -> List[int]: 5 | 6 |         # pq = heapq() 7 | 8 |         pq = [] 9 | 10 |         for item in nums: 11 | 12 |             heapq.heappush(pq,item) 13 | 14 |         ans = [] 15 | 16 |         for idx in range(0,len(nums)): 17 | 18 |             ans.append(heapq.heappop(pq)) 19 | 20 |         return ans 21 | ``` 22 | 23 | 24 | ```python 25 | class Solution: 26 | 27 |     def sortArray(self, nums: List[int]) -> List[int]: 28 | 29 |         nums.sort() 30 | 31 |         return nums 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /src/Java/Random/Divisible sum pair.md: -------------------------------------------------------------------------------- 1 | 2 | ``output:- [1,4][2,3][4,6] 3 | 3`` 4 | ``` 5 | import java.util.*; 6 | 7 | public class Main { 8 | public static void main(String[] args) { 9 | int arr[] = {1,2,3,4,5,6}; 10 | // int arr[]={1,3,2,6,1,2}; 11 | int k = 5; 12 | int ans = 0; 13 | for(int i=0; ist=new Stack(); 4 | for(char c : s.toCharArray()){ 5 | if(c=='(') 6 | st.push(c); 7 | else{ 8 | if(c==')' && !st.isEmpty() && st.peek()=='(') 9 | st.pop(); 10 | else 11 | st.push(c); 12 | } 13 | } 14 | return st.size(); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/15. Daily Temperature #739/Readme.md: -------------------------------------------------------------------------------- 1 | # [**739. Daily Temperatures**](https://leetcode.com/problems/daily-temperatures/) 2 | 3 | ```java 4 | class Solution { 5 | public int[] dailyTemperatures(int[] temp) { 6 | Stack st=new Stack<>(); 7 | int n=temp.length; 8 | int ans[]=new int[n]; 9 | 10 | for(int i=0; i temp[st.peek()]) ans[st.peek()] = i-st.pop() ; 13 | st.push(i); 14 | } 15 | return ans; 16 | } 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /src/Java/LeetCode/Array/Remove Duplicates from Sorted Array.java: -------------------------------------------------------------------------------- 1 | // https://leetcode.com/problems/remove-duplicates-from-sorted-array/ 2 | 3 | // Runtime: 1 ms, faster than 100.00% 4 | class Solution { 5 | public int removeDuplicates(int[] nums) { 6 | if (nums.length==0){ 7 | return 0; 8 | } 9 | int j=0; 10 | for (int i=0; i stack = new Stack(); 5 | for (int i = T.length - 1; i >= 0; --i) { 6 | while (!stack.isEmpty() && T[i] >= T[stack.peek()]) 7 | stack.pop(); 8 | if(stack.isEmpty()) 9 | ans[i]=0; 10 | else 11 | ans[i]=stack.peek() - i; 12 | 13 | stack.push(i); 14 | } 15 | return ans; 16 | } 17 | } -------------------------------------------------------------------------------- /src/Java/Series/Arrays/Array Rotation.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | //array rotation 3 | /* 4 | nR is how much times rotate the array. 5 | */ 6 | public class Main { 7 | public static void main(String[] args) { 8 | int [] arr=new int[]{1,2,3,4,5}; 9 | int nR = 3; 10 | for(int t =0; t st = new Stack<>(); 6 | static void insert_at_bottom(char x) 7 | { 8 | if(st.isEmpty()) 9 | st.push(x); 10 | else 11 | { 12 | char a = st.pop(); 13 | insert_at_bottom(x); 14 | st.push(a); 15 | } 16 | } 17 | 18 | static void reverse() 19 | { 20 | if(st.size() > 1) 21 | { 22 | char x = st.pop(); 23 | reverse(); 24 | insert_at_bottom(x); 25 | } 26 | } 27 | ``` -------------------------------------------------------------------------------- /src/Java/Random/Factor Program/Composite Number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | All the natural numbers which are not prime numbers are composite numbers as 4 | they can be divided by more than two numbers. For example, 6 is a composite 5 | number because it is divisible by 1, 2, 3 and even by 6. 6 | 6 yes 7 | 7 No 8 | */ 9 | public class Main { 10 | public static void main(String[] args) { 11 | int n = 7; 12 | int count=0; 13 | for(int i=1; i<=n; i++){ 14 | if(n%i==0) 15 | count++; 16 | } 17 | if(count>3) 18 | System.out.println("Yes"); 19 | else 20 | System.out.println("No"); 21 | } 22 | } -------------------------------------------------------------------------------- /src/Java/Series/Factor Program/Composite Number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | All the natural numbers which are not prime numbers are composite numbers as 4 | they can be divided by more than two numbers. For example, 6 is a composite 5 | number because it is divisible by 1, 2, 3 and even by 6. 6 | 6 yes 7 | 7 No 8 | */ 9 | public class Main { 10 | public static void main(String[] args) { 11 | int n = 7; 12 | int count=0; 13 | for(int i=1; i<=n; i++){ 14 | if(n%i==0) 15 | count++; 16 | } 17 | if(count>3) 18 | System.out.println("Yes"); 19 | else 20 | System.out.println("No"); 21 | } 22 | } -------------------------------------------------------------------------------- /src/JavaScript/LeetCode/Binary Search/Binary Search.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {number[]} nums 3 | * @param {number} target 4 | * @return {number} 5 | */ 6 | var search = function(nums, target) { 7 | let n = nums.length; 8 | let s = 0; 9 | let e = n-1; 10 | while(s<=e){ 11 | let mid = parseInt( s+(e-s)/2); // Math.floor((s+e)/2); but math high run time. 12 | if(nums[mid]==target){ 13 | return mid; 14 | }else if(target>nums[mid]){ 15 | s=mid+1; 16 | }else{ 17 | e = mid-1; 18 | } 19 | } 20 | return -1; 21 | }; -------------------------------------------------------------------------------- /src/SELF/week 4/Binary Search/Square root of a number.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static int ans; 5 | public static void main(String[] args) { 6 | ans = -1; 7 | Scanner sc = new Scanner(System.in); 8 | int x = sc.nextInt(); 9 | squareRoot(x,1,x); 10 | System.out.print(ans); 11 | } 12 | private static void squareRoot(int x, long start, long end){ 13 | 14 | if(start>end){ 15 | return; 16 | } 17 | long mid = (start+end)/2; 18 | 19 | if(mid*mid<=(long)x){ 20 | ans =(int) mid; 21 | squareRoot(x,mid+1,end); 22 | }else{ 23 | squareRoot(x,start,mid-1); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/09. Trees/03. BinarySearchTrees/05. Flatten BST to Sorted LL GQ/README.md: -------------------------------------------------------------------------------- 1 | # [**Flatten BST to Sorted List**](https://www.geeksforgeeks.org/flatten-bst-to-sorted-list-increasing-order/) 2 | 3 | ```java 4 | static Node prevN=null; 5 | public Node flatten(Node root){ 6 | Node Dummy=new Node(-1); 7 | prevN=Dummy; 8 | 9 | inorder(root); 10 | 11 | return dummy.right; 12 | } 13 | 14 | private void inorder(Node root){ 15 | if(root==null) return; 16 | 17 | inorder(root.left); 18 | 19 | prevN.right=root; 20 | prevN.left=null; 21 | prevN=root; 22 | 23 | inorder(root.right); 24 | } 25 | ``` -------------------------------------------------------------------------------- /src/Java/Series/Arrays/max Frequency Given K elements in Array.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // find frequency of character k in the array. 3 | // input:- 4 | // 5 5 | // 5 3 2 4 5 6 | // 5 7 | 8 | // output: - 2 9 | 10 | public class Main { 11 | public static void main(String[] args) { 12 | Scanner sc=new Scanner(System.in); 13 | 14 | int n = sc.nextInt(); 15 | int arr[] = new int[n]; 16 | 17 | for(int i =0; i pq = new PriorityQueue<>(Comparator.reverseOrder()); 10 | 11 | for (int i = 0; i < arr.length; i++) { 12 | pq.add(arr[i]); 13 | if (pq.size() > k) { 14 | pq.poll(); 15 | } 16 | } 17 | return pq.peek(); 18 | } 19 | 20 | // sorting 21 | // O(N*N) 22 | public static int kthSmallest2(int[] arr, int k) { 23 | 24 | Arrays.sort(arr); 25 | return arr[k]; 26 | } 27 | } 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Java/Series/Arrays/README.md: -------------------------------------------------------------------------------- 1 | 2 | # `Array Question` 🦋 3 | | Difficulty | Tags | Question | Brute Force | Optimal Approach | Company | 4 | | --------------- | ----------- |-----------------|---------|------|---------| 5 | | `easy` | `array` | [Array Rotation Scanner](https://github.com/anishkumar127/Java-Data-Structure-Algorithm-Solutions/blob/main/Arrays/Array%20Rotation%20Scanner.java) | [n^2]() | [o(n)]() | `Google , Facebook` 6 | | `easy` | `array` |[Two Sum]() | [n^2](https://github.com/anishkumar127/Data-Structures-and-Algorithms/blob/main/my%20practice/Two%20Sum%20Array%20O(n%5E2).java.txt) | [o(n)]()| | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Java/Series/today/Array, String , Sorting/ArmStrong Number.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | int n =153; 4 | int arm = 0; 5 | int reminder = 0; 6 | int temp =n; // expriment. original value store. compare to original value. 7 | while(n>0){ // 15>0 8 | reminder= n%10; // reminder 3 9 | arm=(reminder*reminder*reminder)+arm; // 3*3*3 = 27+0 = 27 10 | n=n/10; // 15 11 | } 12 | if(temp==arm){ 13 | System.out.print("YES ArmStrong"); 14 | }else{ 15 | System.out.println("NO"); 16 | } 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /src/Java/Random/Recursion/Max Elements in array Using Recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {8,5,1,3,2,4,6}; 6 | output(arr,0,arr[0]); 7 | } 8 | public static void output(int[] arr, int i ,int max ){ 9 | 10 | if(i==arr.length){ 11 | System.out.print(max); // hit the base condition then print. 12 | return; 13 | } 14 | max = Math.max(arr[i],max); // finding the max. 15 | 16 | // System.out.print(max); // if i do this. it will keep repeatly print 8 8 8 8 max elements. 17 | 18 | output(arr, i+1,max); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /src/Java/Series/OOPS/getter setter/StudentUse.java: -------------------------------------------------------------------------------- 1 | package com.company.Oops; 2 | 3 | public class StudentUse { 4 | 5 | public static void main(String[] args) { 6 | Student s = new Student(); 7 | 8 | // getter 9 | s.getRollNo(); 10 | System.out.println(s.getRollNo()); 11 | 12 | // setter 13 | s.setRollNo(11); 14 | System.out.println(s.getRollNo()); 15 | 16 | /* s.name="Anish"; 17 | //s.rollNo=101; 18 | 19 | System.out.println(s.name); 20 | */ 21 | Student s2= new Student(); 22 | //s2.name="kumar"; 23 | //s2.rollNo=102; 24 | 25 | // System.out.println(s2.name+" "+s2.rollNo); 26 | 27 | 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Java/Series/today/GetNTH Node Linked List.java: -------------------------------------------------------------------------------- 1 | public static int getNth(Node node, int ind) 2 | { 3 | //Your code here 4 | Node currHead = node; 5 | int count =1; 6 | int res = 0; 7 | while(currHead!=null){ 8 | 9 | if(count==ind){ 10 | res = currHead.data; 11 | break; 12 | } 13 | count=count+1; 14 | currHead = currHead.next; 15 | } 16 | return res; 17 | 18 | } 19 | 20 | 21 | /* 22 | Example: 23 | Input: 24 | 2 25 | 6 5 26 | 1 2 3 4 657 76 27 | 10 2 28 | 8 7 10 8 6 1 20 91 21 2 29 | 30 | Output: 31 | 657 32 | 7 33 | */ -------------------------------------------------------------------------------- /src/SELF/week 4/LinkedList GFG/Easy GFG/Linked List Length Even or Odd.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | class Node 4 | { 5 | int data; 6 | Node next; 7 | Node(int d) {data = d; next = null; } 8 | } 9 | */ 10 | /* isLengthEvenorOdd method should return 0 if the length of LL is even 11 | otherwise return 1.*/ 12 | class GFG 13 | { 14 | int isLengthEvenorOdd(Node head1) 15 | { 16 | 17 | Node current_node = head1; 18 | int length =0; 19 | while(current_node!=null){ 20 | length++; 21 | current_node = current_node.next; 22 | } 23 | 24 | if(length%2==0) 25 | return 0; 26 | else return 1; 27 | } 28 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/06. DP/02. Qs/01. nCr/README.md: -------------------------------------------------------------------------------- 1 | # [**nCr**](https://practice.geeksforgeeks.org/problems/ncr1019/1#) 2 | [**Video reference**](https://youtu.be/jIb1W3ObIho) 3 | ```java 4 | class Solution{ 5 | static int nCr(int n, int r) 6 | { 7 | // code here 8 | if(r>n) return 0; 9 | if(n-r0; j--){ 16 | dp[j]=(dp[j]+dp[j-1])%mod; 17 | } 18 | } 19 | return dp[r]; 20 | } 21 | } 22 | ``` -------------------------------------------------------------------------------- /src/Java/Series/today/Array, String , Sorting/Factorial iterative and Recursive.java: -------------------------------------------------------------------------------- 1 | public class Main { 2 | public static void main(String[] args) { 3 | // 5*4*3*2*1=120; 4 | int n = 5; 5 | int fact=1; 6 | for(int i =1; i<=n; i++){ 7 | fact=fact*i; 8 | } 9 | System.out.print(fact); 10 | 11 | // ..... recussion 12 | int Rfact = 1; 13 | Rfact= Recursion(n); 14 | System.out.print(Rfact); 15 | } 16 | public static int Recursion(int n){ 17 | if(n==0){ 18 | return 1; 19 | }else{ 20 | return n*Recursion(n-1); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/SELF/week 1/Recursion/maximum elements using recursion (mY).java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // 8 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {8,5,1,3,2,4,6}; 6 | output(arr,0,arr[0]); 7 | } 8 | public static void output(int[] arr, int i ,int max ){ 9 | 10 | if(i==arr.length){ 11 | System.out.print(max); // hit the base condition then print. 12 | return; 13 | } 14 | max = Math.max(arr[i],max); // finding the max. 15 | 16 | // System.out.print(max); // if i do this. it will keep repeatly print 8 8 8 8 max elements. 17 | 18 | output(arr, i+1,max); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/01. Arrays/18. Best Time to Buy and Sell Stock/i 121/README.md: -------------------------------------------------------------------------------- 1 | # **[121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)** 2 | 3 | **TC = O(N) SC = O(1)** 4 | 5 | ```java 6 | class Solution { 7 | public int maxProfit(int[] arr) { 8 | int n=arr.length; 9 | int profit=0; 10 | int buy=Integer.MAX_VALUE; 11 | for(int i=0;i profit) profit=arr[i]-buy; 14 | } 15 | return profit; 16 | } 17 | } 18 | ``` 19 | 20 | ## **[Video Reference](https://youtu.be/eMSfBgbiEjk)** 21 | -------------------------------------------------------------------------------- /src/Java/Random/Recursion/last occurance elements in array using recursion.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // think as a stack . and return from last. 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {1,2,3,2,3,1}; 6 | int s = 2; 7 | int ans = output(arr,0,s); 8 | System.out.print(ans); 9 | } 10 | private static int output(int arr[], int i, int s){ 11 | if(i==arr.length) return -1; 12 | 13 | int last = output(arr,i+1,s); 14 | 15 | if(last!=-1){ 16 | return last; 17 | } else{ 18 | if(arr[i] == s){ 19 | return i ; 20 | }else{ 21 | return -1; 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/Java/Series/String/Lower To Upper & Upper To Lower Case.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // UpperCase to LowerCase and LowerCase To Uppercase String. 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc=new Scanner(System.in); 7 | char a = sc.next().charAt(0); 8 | 9 | upperCase(a); 10 | lowerCase(a); 11 | } 12 | 13 | public static void upperCase(int a){ 14 | int temp = (int)a; 15 | temp -= 32; 16 | System.out.println((char)temp); 17 | } 18 | public static void lowerCase(int a){ 19 | int temp =(int)a; 20 | temp +=32; 21 | System.out.println((char)temp); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Java/LeetCode/Two Sum II - Input Array Is Sorted.md: -------------------------------------------------------------------------------- 1 | 2 | ``` 3 | class Solution { 4 | public int[] twoSum(int[] numbers, int target) { 5 | int start =0; 6 | int end = numbers.length-1; 7 | int result [] = new int [2]; 8 | while(start st=new Stack<>(); 8 | 9 | for(char c: s.toCharArray()){ 10 | if(c=='(' || c=='{' || c=='[') st.push(c); 11 | else if(!st.isEmpty() && ((c==')'&& st.peek()=='(') || (c=='}'&& st.peek()=='{') || (c==']'&& st.peek()=='[')) ) st.pop(); 12 | else return false; 13 | } 14 | return st.isEmpty(); 15 | } 16 | } 17 | ``` -------------------------------------------------------------------------------- /src/Java/Series/String/Character Print Occur Multi Times In String.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // find and print chracter occur multiple time in the string. 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc=new Scanner(System.in); 6 | String name = sc.nextLine(); 7 | char c = sc.next().charAt(0); 8 | int count =0; 9 | for(int i=0; i=max || root.val<=min) return false; 16 | // if(root.val<=min) return false; 17 | return isValidBST(root.left,min ,root.val) && isValidBST(root.right,root.val,max); 18 | }; 19 | -------------------------------------------------------------------------------- /src/SELF/week 1/find minimum and then find moduler to all %.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Solution 3 | { 4 | public static void main(String[] args) { 5 | Scanner sc=new Scanner(System.in); 6 | int num1=sc.nextInt(); 7 | int num2=sc.nextInt(); 8 | int num3=sc.nextInt(); 9 | int min=Math.min(num1,Math.min(num2,num3)); 10 | // (10,(15,20)); 11 | // System.out.print(min); // 10. 12 | int i; // 10; 13 | for(i=min;i>=1;i--){ 14 | if((num1%i==0) && (num2%i==0) && (num3%i==0)){ 15 | break; 16 | } 17 | } 18 | System.out.println(i); 19 | 20 | // 10%10 == 0; && 15%10 20%10; no. 21 | // 10%5 == 0; && 15% 5 ==0 20%5==0. Yes. 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/1. Singly-LinkList/InterviewBit Qs/01. ReverseLL/solution.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * class ListNode { 4 | * public int val; 5 | * public ListNode next; 6 | * ListNode(int x) { val = x; next = null; } 7 | * } 8 | */ 9 | public class Solution { 10 | public ListNode reverseList(ListNode A) { 11 | ListNode curr=A; 12 | ListNode previous=null; 13 | ListNode nex=null; 14 | while(curr!=null) { 15 | nex=curr.next; 16 | curr.next=previous; 17 | previous=curr; 18 | curr=nex; 19 | } 20 | return previous; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/02. Remove All Adjacent Duplicates In String #1047/Solution_pranay.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String removeDuplicates(String S) { 3 | Stack st=new Stack(); 4 | StringBuilder ans=new StringBuilder(S.length()); 5 | for(int i=0; i st = new Stack<>(); 15 | 16 | for(char ch:s)st.push(ch); 17 | 18 | for(int i=0; i0){ 16 | int rem = n%10; 17 | sum = sum+rem*rem*rem; 18 | n = n/10; 19 | 20 | } 21 | if(temp == sum ){ 22 | System.out.print("YES"); 23 | }else{ 24 | System.out.print("NO"); 25 | } 26 | System.out.print(sum); 27 | 28 | } 29 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/01. LinkList/1. Singly-LinkList/InterviewBit Qs/05. Merge Two Sorted List GQ/Resources.md: -------------------------------------------------------------------------------- 1 | ## Apna College 2 | 3 | **Problem Link** [Merge 2 Sorted List GQ](https://www.interviewbit.com/problems/merge-two-sorted-lists/) 4 | 5 | **Tutorial Link** [Merge 2 Sorted List GQ-Apna College](https://youtu.be/n5_9DMCX0Yk) 6 | 7 | **Code Link** [See my Code here](./solutionApnaCollege.java) 8 | 9 | ## takeUforward 10 | 11 | **Problem Link** [Merge 2 Sorted List GQ](https://www.interviewbit.com/problems/merge-two-sorted-lists/) 12 | 13 | **Tutorial Link** [Merge 2 Sorted List GQ-takeUforward](https://youtu.be/Xb4slcp1U38) 14 | 15 | **Code Link** [See my code here](./solutionStriver.java) 16 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/06. DP/02. Qs/15. maximum sum inc subseq/README.md: -------------------------------------------------------------------------------- 1 | # [**Maximum sum increasing subsequence**](https://practice.geeksforgeeks.org/problems/maximum-sum-increasing-subsequence4749/1#) 2 | 3 | ```java 4 | class Solution 5 | { 6 | public int maxSumIS(int arr[], int n) 7 | { 8 | //code here. 9 | int dp[]=new int[n]; 10 | dp[0]=arr[0]; 11 | int ans=dp[0]; 12 | for(int i=1; i=0; j--){ 15 | if(arr[j] helper_Stack = new Stack<>(); 5 | for(int i=0; i st=new Stack<>(); 7 | 8 | // invalid Parentheses are made either by extra '(' or ')' 9 | for(char c: s.toCharArray()){ 10 | if(c=='(') st.push(c); 11 | else if(!st.isEmpty() && st.peek()=='(' && c==')' ) st.pop(); 12 | else st.push(c); // ( ( ) ) ) ) ( 13 | } 14 | return st.size(); 15 | } 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /src/Python/LeetCode/MajorityElement.md: -------------------------------------------------------------------------------- 1 | 2 | ``` 3 | class Solution(object): 4 | def majorityElement(self, nums): 5 | """ 6 | :type nums: List[int] 7 | :rtype: int 8 | """ 9 | return sorted(nums)[len(nums)/2] 10 | ``` 11 | 12 | ``O(n) time & O(1) space |`` 13 | ``` 14 | class Solution(object): 15 | def majorityElement(self, nums): 16 | """ 17 | :type nums: List[int] 18 | :rtype: int 19 | """ 20 | count = 0 21 | majorElement = None 22 | for num in nums: 23 | if count == 0: 24 | majorElement = num 25 | count += 1 if majorElement == num else -1 26 | return majorElement 27 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/07. Graphs/README.md: -------------------------------------------------------------------------------- 1 | # **Graphs** 2 | 3 | ### Max no. of Edge in graph of N nodes can be **N x (N-1) / 2.** 4 | 5 | ### Min no. of Edge in graph of N nodes can be **N-1.** 6 | 7 | # Prerequisites:- 8 | 9 | - Stack 10 | - Queue 11 | - PriorityQueue 12 | 13 | ## **[Follow this Series by Striver](https://youtube.com/playlist?list=PLgUwDviBIf0rGEWe64KWas0Nryn7SCRWw)** 14 | 15 | - **[15 MST Prim's Algorithm](https://youtu.be/Vw-sktU1zmc)** 16 | - **[16 DisJoint Set Code used in Kruskal's Algorithm](./DisjointSet.java)** 17 | 18 | ## **[See my code here.](./MyGraph.java)** 19 | - **To get the the proper feel of this graph code, I suggest you to complete the functions in ascending order.** 20 | -------------------------------------------------------------------------------- /100 Days Of Code/Neetcode 150/1. Duplicate Integer.md: -------------------------------------------------------------------------------- 1 | ## me 2 | 3 | ```python 4 | class Solution: 5 | 6 |     def hasDuplicate(self, nums: List[int]) -> bool: 7 | 8 |         myset = set(); 9 | 10 |         for val in nums: 11 | 12 |             if val in myset: 13 | 14 |                 return True; 15 | 16 |             else: 17 | 18 |              myset.add(val) 19 | 20 |         return False 21 | ``` 22 | 23 | 24 | ## solution 25 | 26 | ```python 27 | class Solution: 28 | def hasDuplicate(self, nums: List[int]) -> bool: 29 | hashset = set() 30 | 31 | for n in nums: 32 | if n in hashset: 33 | return True 34 | hashset.add(n) 35 | return False 36 | 37 | ``` -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/02. Stack/LeetCode Qs/09. Valid Parentheses #20/Solution simple.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isValid(String s) { 3 | if(s.length()%2!=0) return false; 4 | 5 | Stack st = new Stack(); 6 | for(char c : s.toCharArray()){ 7 | if(c=='(' || c=='[' || c=='{') 8 | st.push(c); 9 | else if(c==']' && !st.isEmpty() && st.peek()=='[') st.pop(); 10 | else if(c==')' && !st.isEmpty() && st.peek()=='(') st.pop(); 11 | else if(c=='}' && !st.isEmpty() && st.peek()=='{') st.pop(); 12 | else st.push(c); 13 | } 14 | return st.isEmpty(); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Java/Random/Recursion/Recursive sum till single digit.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int n = 12345; 6 | int ans = output(n); 7 | System.out.print(ans); 8 | } 9 | private static int output(int n ){ 10 | 11 | if(n<10){ // check 15<10 no then again 2nd round start. 2nd round 6<10 yes then return 6. 12 | return n ; // return 6. 13 | } 14 | int sum =0; // first round 15. 2nd round recursive call again. in 2nd round sum is 6. 15 | while(n>0){ 16 | int rem = n%10; 17 | sum = sum+ rem; 18 | n = n/10; 19 | 20 | } 21 | 22 | return output(sum); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/06. DP/02. Qs/19. max length chain/README.md: -------------------------------------------------------------------------------- 1 | # [**Max length chain**](https://practice.geeksforgeeks.org/problems/max-length-chain/1#) 2 | 3 | 4 | ```java 5 | class GfG 6 | { 7 | int maxChainLength(Pair arr[], int n) 8 | { 9 | // your code here 10 | int dp[]=new int[n]; 11 | Arrays.sort(arr,(a,b)->(a.y - b.y)); 12 | dp[0]=1; 13 | int ans=1; 14 | for(int i=1; i=0; j--){ 17 | if(arr[j].y sort(Stack s) 9 | { 10 | //add code here. 11 | if(s.size() < 2) return s; 12 | else{ 13 | int top = s.pop(); 14 | sort(s); 15 | insertAtPos(s,top); 16 | return s; 17 | } 18 | } 19 | private void insertAtPos(Stack s,int top){ 20 | if(s.isEmpty() || s.peek()<=top){ 21 | s.push(top); return; 22 | } 23 | int topE = s.pop(); 24 | insertAtPos(s,top); 25 | s.push(topE); 26 | } 27 | } 28 | ``` -------------------------------------------------------------------------------- /src/SELF/week 1/String/reverse string.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | // System.out.println("Hello, World!"); 6 | Scanner sc = new Scanner(System.in); 7 | 8 | String st = sc.nextLine(); 9 | 10 | for(int i=st.length()-1; i>=0; i--){ 11 | System.out.print(st.charAt(i)); 12 | } 13 | 14 | 15 | // int i =0; 16 | // int end = st.length()-1; 17 | // while(i>end){ 18 | // int temp = st.charAt(i); 19 | // st.charAt(i) = st.charAt(end); 20 | // st.charAt(end) = temp; 21 | // i++; 22 | // e--; 23 | // } 24 | // System.out.print(st); 25 | } 26 | } -------------------------------------------------------------------------------- /src/SELF/week 4/Binary Search GFG/Searching an element in a sorted array.java: -------------------------------------------------------------------------------- 1 | 2 | class Solution{ 3 | static int searchInSorted(int arr[], int N, int K) 4 | { 5 | 6 | int start =0; 7 | int end = arr.length-1; 8 | 9 | while(start<=end){ 10 | int mid = start+(end-start)/2; 11 | if(arr[mid]==K) 12 | { 13 | return 1; 14 | }else if(arr[mid]>K){ // if middle greater than k so we have to end --; 15 | end = mid-1; 16 | }else{ 17 | start = mid+1; // if middle smaller than k so we have to start++; 18 | } 19 | mid = start+(end-start)/2; 20 | } 21 | return -1; 22 | } 23 | } -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/08. Next Greater Element II #503/README.md: -------------------------------------------------------------------------------- 1 | ## [**503. Next Greater Element II**](https://leetcode.com/problems/next-greater-element-ii/) 2 | 3 | ```java 4 | class Solution { 5 | public int[] nextGreaterElements(int[] nums) { 6 | Stack st=new Stack<>(); 7 | int n=nums.length; 8 | 9 | int res[]=new int[n]; 10 | Arrays.fill(res,-1); 11 | 12 | for(int i=0; i nums[st.peek()]){ 15 | res[st.pop()] = ele; 16 | } 17 | st.push(i%n); 18 | } 19 | return res; 20 | } 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /src/Java/GFG/Print alternate elements of an array .md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ``` 4 | class GfG 5 | { 6 | public static void print(int arr[], int n) 7 | { 8 | // your code here 9 | for(int i=0; i0){ 19 | int t = x%10; 20 | sum = (sum*10)+t; 21 | x = x/10; 22 | } 23 | System.out.print(sum); 24 | } 25 | } 26 | ``` -------------------------------------------------------------------------------- /src/Java/Series/Arrays/Find First Index Of X In Arrays.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // find the first index of x in array 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc= new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | int [] arr = new int[n]; 8 | // for input 9 | for(int input = 0; input0){ 18 | if(first%ans ==0 && second%ans ==0){// here 75%15 ==0; and 90%15 ==0 so break loop 19 | break; // if match break the loop. 20 | } 21 | ans--; // keep decreasing 75 until match the condition. in if statement. 22 | } 23 | System.out.print(ans); // printed 15 here. 24 | } 25 | } -------------------------------------------------------------------------------- /src/SELF/week 4/Binary Search/binary search descending order.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | int arr[] = {20,17,15,14,13,10,8,7,4}; 6 | int n = arr.length; 7 | int t = 4; 8 | int result= search(arr,0,n-1,t); 9 | System.out.println(result); 10 | } 11 | private static int search(int[] arr,int start,int end, int t){ 12 | 13 | while(start<=end){ 14 | int mid = start+(end-start)/2; 15 | 16 | if(arr[mid]==t){ 17 | return mid; 18 | }else if(t0){ 12 | if(arr[i]-arr[i-1] sb1.append((char)c)); 9 | System.out.print(sb1); //output:- progamin 10 | 11 | System.out.println(); 12 | //Approach 2; 13 | String name1 ="programming"; 14 | StringBuilder sb2 = new StringBuilder(); 15 | for(int i =0; i inOrder(Node root) { 15 | // Code 16 | ArrayList ans = new ArrayList<>(); 17 | helper(root,ans); 18 | return ans; 19 | } 20 | private void helper(Node root, ArrayListrefVal){ 21 | if(root==null) return; 22 | helper(root.left,refVal); 23 | refVal.add(root.data); 24 | helper(root.right,refVal); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/01. DataStructures/03. Queue/Basic Operations/07. Priority Queue/KLargestElement.java: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | //Function to return k largest elements from an array. 4 | public static ArrayList kLargest(int a[], int n, int k) 5 | { 6 | PriorityQueue pq=new PriorityQueue<>(); 7 | for(int i=0;i ans =new ArrayList<>(pq); 18 | Collections.sort(ans,Collections.reverseOrder()); 19 | return ans; 20 | } 21 | } -------------------------------------------------------------------------------- /src/Java/Series/Arrays/non repeated elements O(n^2) Nested Loop with count.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | /* 3 | input:- 4,2,4,2,5,-1,-1,6 4 | output:- 5 6 5 | 6 | TC:- O(n^2) 7 | 8 | */ 9 | public class Main { 10 | public static void main(String[] args) { 11 | int arr [] = {4,2,4,2,5,-1,-1,6}; 12 | int n = arr.length; 13 | int count; 14 | for( int i =0; i=0; j--){ 14 | if(Math.abs(arr[j]-arr[i])==1) max=Math.max(dp[j],max); 15 | } 16 | dp[i]=max+1; 17 | ans=Math.max(dp[i],ans); 18 | } 19 | return ans; 20 | } 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/06. DP/02. Qs/28. Kadane's algo/README.md: -------------------------------------------------------------------------------- 1 | # [**Largest sum in a subarray**](https://practice.geeksforgeeks.org/problems/kadanes-algorithm-1587115620/1#) 2 | 3 | ## Using DP 4 | ```java 5 | class Solution{ 6 | 7 | // arr: input array 8 | // n: size of array 9 | //Function to find the sum of contiguous subarray with maximum sum. 10 | long maxSubarraySum(int arr[], int n){ 11 | 12 | // Your code here 13 | long s=arr[0],bs=arr[0]; 14 | for(int i=1;i=0) s+=arr[i]; 16 | else s=arr[i]; 17 | 18 | bs=Math.max(bs,s); 19 | } 20 | return bs; 21 | } 22 | } 23 | ``` 24 | ## [**Video Reference**](https://youtu.be/VMtyGnNcdPw) -------------------------------------------------------------------------------- /src/DSA Complete - Java/02. Algorithms/10. Stack & Queue/07. Next Greater Element I #496/Solution_Optimised.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] nextGreaterElement(int[] nums1, int[] nums2) { 3 | HashMap map=new HashMap(); // hash map is use to store greatestRightSide element(as a value) for each element in nums2(as a key) 4 | Stack st=new Stack(); 5 | 6 | for(int ele:nums2){ 7 | while(!st.isEmpty() && ele>st.peek()){ 8 | map.put(st.pop(),ele); 9 | } 10 | st.push(ele); 11 | } 12 | 13 | for(int i=0;i=0; i--){ 15 | if(x == arr[i]){ 16 | System.out.println("First index of x in array"+" "+i); 17 | return; 18 | } 19 | } 20 | System.out.println("-1"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Java/Series/String/String Anagram Or NOT.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // check is string Anagram or not. 3 | public class Main { 4 | public static void main(String[] args) { 5 | String a="anish"; 6 | String b="kumar"; 7 | char [] a1= a.toCharArray(); 8 | char [] b1= b.toCharArray(); 9 | 10 | Arrays.sort(a1); 11 | Arrays.sort(b1); 12 | if(a.length()!=a.length()){ 13 | System.out.print("Not a anagram"); 14 | return; 15 | } 16 | 17 | for(int i=0; i