├── Data Structures in Java ├── BST - I │ ├── 1. isBST.PNG │ ├── 2. BST time complexity.PNG │ ├── 3. Traversal in BST.PNG │ ├── Assignment │ │ ├── BSToLinkedList.java │ │ ├── LowestCommonAncestorInBST.java │ │ └── ReplaceWithLargerNodesSum.java │ ├── FindNodeInBST.java │ ├── NodesBetweenK1&K2.java │ └── SortedArrayToBST.java ├── BST - II │ ├── 1. BST.PNG │ ├── 2. Time Complexity.PNG │ ├── 3. Height of BST.PNG │ ├── 4. Height of BST II.PNG │ ├── 5. Insertion in BST.PNG │ ├── 6. Deleting a node.PNG │ ├── 7. Insertion-Deletion in BST.PNG │ ├── Assignment │ │ ├── LargestBSTInefficient.java │ │ ├── LevelWiseLinkedList.java │ │ └── PairSumInBST.java │ └── BSTClass.java ├── Backtracking │ ├── N-Queens.java │ ├── PathFromNodeToRoot.java │ ├── RatInAMaze.java │ └── RatInAMazePrintAllPaths.java ├── Binary Trees - I │ ├── 1. Binary Tree Node.PNG │ ├── 2. Input Binary Tree.PNG │ ├── 3. Binary Tree Levelwise.PNG │ ├── 4. Height of Tree.PNG │ ├── Assignment │ │ ├── IsNodePresent.java │ │ └── NodesWithoutSiblings.java │ ├── HeightOfTree.java │ ├── NodesGreaterThanX.java │ ├── PostOrderTraversal.java │ ├── PreOrderTraversal.java │ ├── ReplaceNodeWithDepth.java │ └── SumOfNodes.java ├── Binary Trees - II │ ├── Assignment │ │ ├── CreateAndInsertDuplicateNode.java │ │ ├── LevelOrderTraversal.java │ │ ├── MinAndMax.java │ │ ├── NodesAtKDistanceFromNode.java │ │ └── PathSumRootToLeaf.java │ ├── ConstructTreeUsingPostOrderAndInorder.java │ ├── ConstructTreeUsingPreOrderAndInorder.java │ ├── DiameterOfBinaryTree.java │ ├── Inorder PreOrder PostOrder.PNG │ ├── MirrorBinaryTree.java │ └── PrintLevelWise.java ├── Hashmaps │ ├── 1. Time Complexity.PNG │ ├── 10. Rehashing.PNG │ ├── 2. Return type.PNG │ ├── 3. Hashmap Function.PNG │ ├── 4. Hash code.PNG │ ├── 5. Hash function.PNG │ ├── 6. Hashing 1.PNG │ ├── 7. Hashing 2.PNG │ ├── 8. Load Factor.PNG │ ├── 9, Time Complexity.PNG │ ├── Assignment │ │ └── ExtractUniqueCharacters.java │ ├── MaxFrequencyNumber.java │ ├── PairSumToZero.java │ └── PrintArrayIntersection.java ├── Linked List - I │ ├── 1. Collection class for Dynamic Array.PNG │ ├── 10. Search in LL.PNG │ ├── 11. Add element at last.PNG │ ├── 12. Insert at 2nd position.PNG │ ├── 13. Operations in O(1).PNG │ ├── 14. Operations in O(1).PNG │ ├── 2. Size of Arraylist.PNG │ ├── 3. ArrayList of Integers.PNG │ ├── 4. Figure out Element.PNG │ ├── 5. Figure out correct statement.PNG │ ├── 6. Linked List use case.PNG │ ├── 7. What is the output.PNG │ ├── 8. Predict the output.PNG │ ├── 9. Find output.PNG │ ├── Assignment │ │ ├── AppendLastNToFirst.java │ │ ├── CheckPalindromeList.java │ │ ├── EliminateDuplicates.java │ │ ├── FindNodeInLInkedList.java │ │ └── PrintReversedLinkedList.java │ ├── DeleteNodeAtGivenPosition.java │ ├── InsertNodeinLinkedList.java │ ├── LengthOfLinkedList.java │ └── PrintIthNode.java ├── Linked List - II │ ├── 1. Correct output.PNG │ ├── 2. Correct output.PNG │ ├── 3.Traversal.PNG │ ├── 4. Double LL.PNG │ ├── 5. Circular LL.PNG │ ├── 6. Time complexity.PNG │ ├── 7. Concat linked list.PNG │ ├── 8. Circular Double LL.PNG │ ├── Assignment │ │ ├── Bubble sort on linked list.txt │ │ ├── Delete every M nodes.txt │ │ ├── Even after Odd Linked List.txt │ │ ├── Find node in linked list using recursion.txt │ │ ├── Reverse every k elements of the linked list.txt │ │ └── Swap two nodes of linked list.txt │ ├── Delete Node Recursively.txt │ ├── Merge 2 sorted lists.txt │ ├── Merge sort linked list.txt │ ├── Mid point of linked list.txt │ └── Reverse Linked List recursively.txt ├── OOPS - I │ ├── 1. Correct Statement.PNG │ ├── 10. Fill the output.PNG │ ├── 11. Fill the output.PNG │ ├── 12. Keyword.PNG │ ├── 13. Predict the output.PNG │ ├── 14. Predict the output.PNG │ ├── 15. Final Keyword.PNG │ ├── 16. Predict the output.PNG │ ├── 17. Predict the output.PNG │ ├── 18. Find the error.PNG │ ├── 19. Predict the output.PNG │ ├── 2. Object Creation.PNG │ ├── 20. Find the error.PNG │ ├── 3. Predict the output.PNG │ ├── 4. Find the error.PNG │ ├── 5. Possible Output.PNG │ ├── 6. Access Modifiers.PNG │ ├── 7. Check for error.PNG │ ├── 8. Predict the output.PNG │ ├── 9. Predict the output.PNG │ ├── ComplexNumbers.java │ └── Polynomial.java ├── OOPS - II │ ├── 1. OOPS components.PNG │ ├── 10. Predict the output.PNG │ ├── 11. Predict the output.PNG │ ├── 12. Predict the output.PNG │ ├── 13. Correct option.PNG │ ├── 14. Correct option.PNG │ ├── 15. Predict the output.PNG │ ├── 16. Predict the output.PNG │ ├── 17, What it the output.PNG │ ├── 18. What is the output.PNG │ ├── 19. What is the output.PNG │ ├── 2. Correct Statement.PNG │ ├── 20. Correct statement.PNG │ ├── 21. Fill the output.PNG │ ├── 22. Predict the output.PNG │ ├── 23. Predict the output.PNG │ ├── 24. Predict the output.PNG │ ├── 25. What is the output.PNG │ ├── 26, What is the output.PNG │ ├── 27. Valid Statement.PNG │ ├── 3. Keyword.PNG │ ├── 4. Properties of a class.PNG │ ├── 5. Predict the output.PNG │ ├── 6. Properties of class.PNG │ ├── 7. Predict the output.PNG │ ├── 8. Predict the output.PNG │ ├── 9. Predict the output.PNG │ └── OOPs notes.pdf ├── Queue │ ├── 1. Queue.PNG │ ├── 10. Predict the output.PNG │ ├── 11. Predict the output.PNG │ ├── 12. Queue to stack.PNG │ ├── 2. Correct Order.PNG │ ├── 3. Function.PNG │ ├── 4 Queue Implementation.PNG │ ├── 5. Insert Element.PNG │ ├── 6. Size of Circular Queue.PNG │ ├── 7. Time Complexity.PNG │ ├── 8. LL queue.PNG │ ├── 9. Stack and Queue.PNG │ ├── Assignment │ │ ├── ReverseKElements.class │ │ └── ReverseQueue.java │ ├── QueueUsingLinkedList.class │ └── StackUsingQueue.class ├── Recursion - I │ ├── 1. What is the output.PNG │ ├── 2. What is the output.PNG │ ├── 3. What is the output.PNG │ ├── CalculatePower.java │ ├── CheckNumberInArray.java │ ├── FirstIndex.java │ ├── FirstNNaturalNumbers.java │ ├── LastIndex.java │ ├── NumberOfDigits.java │ ├── Recursion Notes.pdf │ └── SumOfArray.java ├── Recursion - II │ ├── MergeSort.java │ ├── QuickSort.java │ ├── RemoveDuplicates.java │ ├── RemoveX.java │ └── TowerOfHanoi.java ├── Recursion Assignment │ ├── CheckAB.java │ ├── CheckPalindrome.java │ ├── CountZeros.java │ ├── GeometricSum.java │ ├── Multiplication.java │ ├── PairStar.java │ ├── StairCase.java │ ├── StringToInteger.java │ └── SumOfDigits.java ├── Stacks │ ├── 1. Index problem.PNG │ ├── 10. Predict the output.PNG │ ├── 11. Double Stack.PNG │ ├── 12. Time Complexity.PNG │ ├── 13. LL Stacks.PNG │ ├── 14. Time Complexity.PNG │ ├── 15. Predict the output.PNG │ ├── 16. Predict the output.PNG │ ├── 17. Predict the output.PNG │ ├── 18. Predict the output.PNG │ ├── 2. Stack.PNG │ ├── 3. Size of stack.PNG │ ├── 4. Sum of stack.PNG │ ├── 5. Size Function.PNG │ ├── 6. Correct Statement.PNG │ ├── 7. Stack Implementation.PNG │ ├── 8. Stack Implementation.PNG │ ├── 9. Correct Statement.PNG │ ├── Assignment │ │ ├── Check redundant brackets.txt │ │ ├── Minimum bracket reversal.txt │ │ └── Stock Span.txt │ ├── Brackets balanced.txt │ ├── Reverse a stack.txt │ └── Stack using linked list.txt ├── Test 1 │ ├── 1. Recurrence Relation for Tower of Hanoi.PNG │ ├── 2. Complexity of different operations in a sorted array.PNG │ ├── 3. Complexity of Recurrence Relation.PNG │ ├── DoesSContainT.java │ ├── MaximumProfit.java │ └── SplitArray.java ├── Test 2 │ ├── DeleteAlternateNodes.java │ ├── DoubleEndedQueue.java │ └── NextNumber.java ├── Time Complexity │ ├── 1. Complexity.PNG │ ├── 2. Number of operations.PNG │ ├── 3 Number of operations.PNG │ ├── 4. Time Complexity of Code.PNG │ ├── 5. Time complexity of code.PNG │ ├── 6. Time complexity.PNG │ ├── 7. Time complexity of code.PNG │ ├── 8. Time complexity of code.PNG │ ├── 9. Merging 2 sorted arrays.PNG │ ├── ArrayEquilibrium.java │ ├── Assignment │ │ ├── DuplicateInArray.java │ │ ├── FindUnique.java │ │ ├── PairSum.java │ │ ├── RotateArray.java │ │ └── TripletSum.java │ └── IntersectionOfArrays.java ├── Time and Space Complexity │ ├── 1. Recurrence for Merge Sort.PNG │ ├── 2. Merge Sort.PNG │ ├── 3. What is the time complexity.PNG │ ├── 4. What is the time complexity.PNG │ ├── 5. Fibonacci.PNG │ ├── 6. Merge Sort Space.PNG │ └── 7. Fibonacci.PNG └── Trees │ ├── CheckNodeExistence.java │ ├── CountAllLeafNodes.java │ ├── GenericTreeLevelWise.java │ ├── HeightOfGenericTree.java │ ├── NodesGreaterThanX.java │ ├── NumberOFNodesGreaterThanX.java │ ├── PostOrderTraversalGenericTree.java │ ├── ReplaceWithLargerNodesSum.java │ └── SumOfAllNodes.java ├── Introduction to Java ├── Lecture 10 Arrays 1 │ ├── 1. Correct Statement.PNG │ ├── 10. Predict the output.PNG │ ├── 11. Predict the output.PNG │ ├── 12. Predict the output.PNG │ ├── 2. Predict the output.PNG │ ├── 3. Predict the output.PNG │ ├── 4. Predict the output.PNG │ ├── 5. Predict the output.PNG │ ├── 6. Length of array.PNG │ ├── 7. Non Primitives.PNG │ ├── 8. Predict the output.PNG │ ├── 9. Predict the output.PNG │ ├── ArrangeNumbers.java │ ├── Assignment │ │ ├── ArrayIntersection.java │ │ ├── FindDuplicate.java │ │ ├── FindUnique.java │ │ ├── PairSum.java │ │ ├── SortZeroOne.java │ │ └── TripletSum.java │ ├── LinearSearch.java │ ├── SumOfArray.java │ └── SwapAlternate.java ├── Lecture 11 Arrays 2 │ ├── Assignment │ │ ├── CheckArrayRotation.java │ │ ├── PushZerosToEnd.java │ │ ├── RotateArray.java │ │ ├── SecondLargestInArray.java │ │ ├── SortZeroOneTwo.java │ │ └── SumOfTwoArrays.java │ ├── BinarySearch.java │ ├── BubbleSort.java │ ├── InsertionSort.java │ ├── Merge2SortedArrays.java │ └── SelectionSort.java ├── Lecture 12 Stings │ ├── 1. Correct Statement.PNG │ ├── 10. Predict teh output.PNG │ ├── 11. Output problem.PNG │ ├── 12. Output problem.PNG │ ├── 13. Predict the output.PNG │ ├── 14. StringBuffer.PNG │ ├── 15. Predict the output.PNG │ ├── 2. Return Type.PNG │ ├── 3. Predict the output.PNG │ ├── 4. Predict the output.PNG │ ├── 5. Predict the output.PNG │ ├── 6. Predict the output.PNG │ ├── 7. Correct Statement.PNG │ ├── 8. Predict the output.PNG │ ├── 9. Predict the output.PNG │ ├── AllSubstrings.java │ ├── Assignment │ │ ├── CheckPermutation.java │ │ ├── CompressString.java │ │ ├── HighestOccuringCharacter.java │ │ ├── RemoveCharacter.java │ │ ├── RemoveConsecutiveDuplicates.java │ │ └── ReverseEachWord.java │ ├── CountWords.java │ ├── ReverseStringWordwise.java │ ├── String Notes.pdf │ └── StringPalindrome.java ├── Lecture 13 Two Dimensional Arrays │ ├── 1. Number of Elements.PNG │ ├── 10. Return type.PNG │ ├── 11. Predict the output.PNG │ ├── 12. Predict the output.PNG │ ├── 13. Predict the output.PNG │ ├── 14. Predict the output.PNG │ ├── 15. Declare a 2d array.PNG │ ├── 2. 2-d array.PNG │ ├── 3. Predict the output.PNG │ ├── 4. Predict the output.PNG │ ├── 5. Fill the output.PNG │ ├── 6. Predict the output.PNG │ ├── 8. Length of 2d array.PNG │ ├── 9, Predict the output.PNG │ ├── Assignment │ │ ├── BoundaryDiagonalSum.java │ │ └── WavePrint.java │ ├── LargestRowOrColumn.java │ └── RowWiseSum.java ├── Lecture 4 Conditionals and Loops │ ├── 1. Error in code.txt │ ├── 10. Find the Output.PNG │ ├── 11. Find the output.PNG │ ├── 12. Find the output.PNG │ ├── 13. Find Character Case.txt │ ├── 14. Number of hellos.PNG │ ├── 15. Number of hello 2.PNG │ ├── 16. Same output.PNG │ ├── 17. Fahrenheit to Celsius Table.txt │ ├── 18. Primality Check.PNG │ ├── 19. Find the output.PNG │ ├── 2. Find the output.txt │ ├── 20. Check the error.PNG │ ├── 21. Check the error.PNG │ ├── 22. Check the error.PNG │ ├── 23. Check the error.PNG │ ├── 24. What is the output.PNG │ ├── 3. Predict the output.txt │ ├── 4.Find output.txt │ ├── 5. Find Output.PNG │ ├── 6. Find the Output.PNG │ ├── 7. Figure out the output.PNG │ ├── 8. What will be the output.PNG │ ├── 9. Positive Negative.PNG │ └── Assignment- Conditionals and Loops │ │ ├── Factors.java │ │ ├── FindPowerOfNumber.java │ │ ├── MultiplicationTable.java │ │ ├── SumEvenOdd.java │ │ └── totalSalary.java ├── Lecture 5 Patterns - 1 │ ├── AlphaPattern.java │ ├── CharacterPattern.java │ ├── InterestingAlphabets.java │ ├── ReverseNumberPattern.java │ ├── SquarePattern.java │ ├── TriangularNumberPattern.java │ ├── TriangularStarPattern.java │ └── test.java ├── Lecture 6 Patterns - 2 │ ├── Assignment │ │ ├── Half Diamond Pattern.txt │ │ ├── Odd Square.txt │ │ ├── Parallelogram Pattern.txt │ │ └── Sum Pattern.txt │ ├── Diamond of stars.txt │ ├── Inverted Number Pattern.txt │ ├── Mirror Image Number Pattern.txt │ ├── Star Pattern.txt │ └── Triangle of Numbers.txt ├── Lecture 7 Operators and For loops │ ├── 1. Bitwise output.PNG │ ├── 10. Guess the output.PNG │ ├── 11. Correct output.PNG │ ├── 12. Guess the output.PNG │ ├── 13. For loop.PNG │ ├── 14. Guess the output.PNG │ ├── 15. What is the output.PNG │ ├── 16. What is the output.PNG │ ├── 17. What is the output.PNG │ ├── 18. Guess the output.PNG │ ├── 19. Correct output.PNG │ ├── 2. Find error.PNG │ ├── 20. Find the error.PNG │ ├── 21. Skip iteration.PNG │ ├── 22. What is the output.PNG │ ├── 23. What is the output.PNG │ ├── 24. What is the output.PNG │ ├── 25. What is the output.PNG │ ├── 3. Bitwise Operator.PNG │ ├── 4. Correct output.PNG │ ├── 5. Bitwise operator.PNG │ ├── 6. Guess the output.PNG │ ├── 7. Guess the output.PNG │ ├── 8. Guess the output.PNG │ ├── 9. Guess the output.PNG │ ├── All Prime Numbers.txt │ ├── Assignment │ │ ├── Binary to decimal.txt │ │ ├── Check Number sequence.txt │ │ ├── Decimal to Binary.txt │ │ ├── Reverse of a number.txt │ │ ├── Square Root (Integral).txt │ │ ├── Sum or Product.txt │ │ └── Terms of AP.txt │ └── Notes.pdf ├── Lecture 8 Test 1 │ ├── CheckArmstrong.java │ ├── NumberStarPattern1.java │ └── ZerosAndStarPattern.java ├── Lecture 9 Functions & Scope │ ├── 1. Predict the output.PNG │ ├── 10. Check for error.PNG │ ├── 11. Predict the output.PNG │ ├── 12. Fill the output.PNG │ ├── 13. Fill the output.PNG │ ├── 14. Fill the output.PNG │ ├── 15. Check the error.PNG │ ├── 16. Check the error.PNG │ ├── 17. Check prime.PNG │ ├── 18. Predict the output.PNG │ ├── 19. Predict the output.PNG │ ├── 2. Return type.PNG │ ├── 3. Return type.PNG │ ├── 4. Fill the output.PNG │ ├── 5. Find the output.PNG │ ├── 6. Return type.PNG │ ├── 7. Check the error.PNG │ ├── 8. Check for error.PNG │ ├── 9. Predict the output.PNG │ ├── FahrenheitToCelcius.java │ ├── FibonacciTest.java │ └── Functions notes.pdf └── Test 2 │ ├── ArrayLeaders.java │ ├── MinimumWordLength.java │ └── Print2dArray.java └── README.md /Data Structures in Java/BST - I/1. isBST.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - I/1. isBST.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/2. BST time complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - I/2. BST time complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/3. Traversal in BST.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - I/3. Traversal in BST.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/Assignment/LowestCommonAncestorInBST.java: -------------------------------------------------------------------------------- 1 | public class LowestCommonAncestorInBSR { 2 | 3 | /* Binary Tree Node class 4 | * 5 | * class BinaryTreeNode { 6 | T data; 7 | BinaryTreeNode left; 8 | BinaryTreeNode right; 9 | 10 | public BinaryTreeNode(T data) { 11 | this.data = data; 12 | } 13 | } 14 | */ 15 | 16 | public static int lcaInBST(BinaryTreeNode root , int a , int b){ 17 | // Write your code here 18 | if(root == null) 19 | return 0; 20 | 21 | if(a < root.data && b < root.data) 22 | return lcaInBST(root.left, a, b); 23 | else if(a > root.data && b > root.data) 24 | return lcaInBST(root.right, a, b); 25 | else 26 | return root.data; 27 | } 28 | } -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/Assignment/ReplaceWithLargerNodesSum.java: -------------------------------------------------------------------------------- 1 | class Sum 2 | { 3 | int sum = 0; 4 | } 5 | public class ReplaceWithLargerNodesSum { 6 | 7 | /* Binary Tree Node class 8 | * 9 | * class BinaryTreeNode { 10 | T data; 11 | BinaryTreeNode left; 12 | BinaryTreeNode right; 13 | 14 | public BinaryTreeNode(T data) { 15 | this.data = data; 16 | } 17 | } 18 | */ 19 | 20 | 21 | public static void replaceWithLargerNodesSum(BinaryTreeNode root) { 22 | // Write your code here 23 | Sum s = new Sum(); 24 | replace(root, s); 25 | } 26 | 27 | private static void replace(BinaryTreeNode node, Sum S){ 28 | // Base Case 29 | if (node == null) 30 | return; 31 | 32 | // Recur for right subtree 33 | replace(node.right, S); 34 | 35 | // Now *sum has sum of nodes in right subtree, add 36 | // root->data to sum and update root->data 37 | S.sum = S.sum + node.data; 38 | node.data = S.sum; 39 | 40 | // Recur for left subtree 41 | replace(node.left, S); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/FindNodeInBST.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | /* Binary Tree Node class 4 | * 5 | * class BinaryTreeNode { 6 | T data; 7 | BinaryTreeNode left; 8 | BinaryTreeNode right; 9 | 10 | public BinaryTreeNode(T data) { 11 | this.data = data; 12 | } 13 | } 14 | */ 15 | 16 | public static BinaryTreeNode searchInBST(BinaryTreeNode root , int k){ 17 | if(root == null) 18 | return null; 19 | 20 | if(k < root.data) 21 | return searchInBST(root.left, k); 22 | else if(k > root.data) 23 | return searchInBST(root.right, k); 24 | else 25 | return root; 26 | } 27 | } -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/NodesBetweenK1&K2.java: -------------------------------------------------------------------------------- 1 | public class NodesBetweenK1&K2 { 2 | 3 | /* Binary Tree Node class 4 | * 5 | * class BinaryTreeNode { 6 | T data; 7 | BinaryTreeNode left; 8 | BinaryTreeNode right; 9 | 10 | public BinaryTreeNode(T data) { 11 | this.data = data; 12 | } 13 | } 14 | */ 15 | 16 | public static void printNodeFromK1ToK2(BinaryTreeNode root,int k1,int k2){ 17 | if(root == null) 18 | return; 19 | 20 | if(root.data > k1 && root.data > k2) 21 | printNodeFromK1ToK2(root.left, k1, k2); 22 | else if(root.data < k1 && root.data < k2) 23 | printNodeFromK1ToK2(root.right, k1, k2); 24 | else{ 25 | printNodeFromK1ToK2(root.left, k1, k2); 26 | System.out.print(root.data + " "); 27 | printNodeFromK1ToK2(root.right, k1, k2); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Data Structures in Java/BST - I/SortedArrayToBST.java: -------------------------------------------------------------------------------- 1 | public class SortedArrayToBST { 2 | 3 | /* 4 | * Binary Tree Node class 5 | * 6 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 7 | * right; 8 | * 9 | * public BinaryTreeNode(T data) { this.data = data; } } 10 | */ 11 | 12 | public static BinaryTreeNode SortedArrayToBST(int[] arr) { 13 | if (arr.length == 0) 14 | return null; 15 | 16 | return convertToBST(arr, 0, arr.length - 1); 17 | } 18 | 19 | private static BinaryTreeNode convertToBST(int[] arr, int left, int right) { 20 | if (left > right) 21 | return null; 22 | 23 | int mid = left + (right - left) / 2; 24 | BinaryTreeNode root = new BinaryTreeNode<>(arr[mid]); 25 | root.left = convertToBST(arr, left, mid - 1); 26 | root.right = convertToBST(arr, mid + 1, right); 27 | return root; 28 | } 29 | } -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/1. BST.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/1. BST.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/2. Time Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/2. Time Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/3. Height of BST.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/3. Height of BST.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/4. Height of BST II.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/4. Height of BST II.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/5. Insertion in BST.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/5. Insertion in BST.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/6. Deleting a node.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/6. Deleting a node.PNG -------------------------------------------------------------------------------- /Data Structures in Java/BST - II/7. Insertion-Deletion in BST.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/BST - II/7. Insertion-Deletion in BST.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/1. Binary Tree Node.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Binary Trees - I/1. Binary Tree Node.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/2. Input Binary Tree.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Binary Trees - I/2. Input Binary Tree.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/3. Binary Tree Levelwise.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Binary Trees - I/3. Binary Tree Levelwise.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/4. Height of Tree.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Binary Trees - I/4. Height of Tree.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/Assignment/IsNodePresent.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree and an integer x, check if node with data x is present in the input binary tree or not. Return true or false. 2 | Input format : 3 | Line 1 : Elements in level order form (separated by space) 4 | (If any node does not have left or right child, take -1 in its place) 5 | Line 2 : Integer x 6 | Output Format : 7 | true or false 8 | Sample Input : 9 | 8 3 10 1 6 -1 14 -1 -1 4 7 13 -1 -1 -1 -1 -1 -1 -1 10 | 7 11 | Sample Output : 12 | true */ 13 | 14 | public class IsNodePresent { 15 | 16 | /* 17 | * Binary Tree Node class 18 | * 19 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 20 | * right; 21 | * 22 | * public BinaryTreeNode(T data) { this.data = data; } } 23 | */ 24 | 25 | public static boolean isNodePresent(BinaryTreeNode root, int x) { 26 | /* 27 | * Your class should be named Solution Don't write main(). Don't read input, it 28 | * is passed as function argument. Return output and don't print it. Taking 29 | * input and printing output is handled automatically. 30 | */ 31 | if (root == null) 32 | return false; 33 | if (root.data == x) 34 | return true; 35 | else 36 | return isNodePresent(root.left, x) || isNodePresent(root.right, x); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/Assignment/NodesWithoutSiblings.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree, print all nodes that don’t have a sibling. 2 | Edit : Print the elements in different lines. And order of elements doesn't matter. 3 | Input format : 4 | Elements in level order form (separated by space). If any node does not have left or right child, take -1 in its place. 5 | Output format : 6 | Print nodes separated by new line. 7 | Sample Input : 8 | 5 6 10 2 3 -1 -1 -1 -1 -1 9 -1 -1 9 | Sample Output : 10 | 9 */ 11 | 12 | import java.util.ArrayList; 13 | 14 | public class NodesWithoutSiblings { 15 | 16 | /* 17 | * Binary Tree Node class 18 | * 19 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 20 | * right; 21 | * 22 | * public BinaryTreeNode(T data) { this.data = data; } } 23 | */ 24 | 25 | public static void printNodesWithoutSibling(BinaryTreeNode root) { 26 | 27 | // Write your code here 28 | if (root == null) 29 | return; 30 | if (root.left == null && root.right == null) { 31 | // System.out.println(-1); 32 | return; 33 | } 34 | 35 | if (root.left != null && root.right == null) 36 | System.out.println(root.left.data); 37 | 38 | if (root.right != null && root.left == null) 39 | System.out.println(root.right.data); 40 | 41 | printNodesWithoutSibling(root.left); 42 | printNodesWithoutSibling(root.right); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/HeightOfTree.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree, find and return the height of given tree. 2 | Input format : 3 | Nodes in the level order form (separated by space). If any node does not have left or right child, take -1 in its place 4 | Output format : 5 | Height 6 | Constraints : 7 | 1 <= N <= 10^5 8 | Sample Input : 9 | 10 10 | 9 11 | 4 12 | -1 13 | -1 14 | 5 15 | 8 16 | -1 17 | 6 18 | -1 19 | -1 20 | 3 21 | -1 22 | -1 23 | -1 24 | Sample Output : 25 | 5 */ 26 | 27 | public class HeightOfTree { 28 | 29 | /* 30 | * Binary Tree Node class 31 | * 32 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 33 | * right; 34 | * 35 | * public BinaryTreeNode(T data) { this.data = data; } } 36 | */ 37 | public static int height(BinaryTreeNode root) { 38 | /* 39 | * Your class should be named Solution Don't write main(). Don't read input, it 40 | * is passed as function argument. Return output and don't print it. Taking 41 | * input and printing output is handled automatically. 42 | */ 43 | if (root == null) 44 | return 0; 45 | 46 | int heightOfTree = Math.max(height(root.left), height(root.right)); 47 | return 1 + heightOfTree; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/NodesGreaterThanX.java: -------------------------------------------------------------------------------- 1 | /* Given a Binary Tree and an integer x, find and return the count of nodes which are having data greater than x. 2 | Input format : 3 | Line 1 : Elements in level order form (separated by space) 4 | (If any node does not have left or right child, take -1 in its place) 5 | Line 2 : Integer x 6 | Output Format : 7 | count 8 | Sample Input : 9 | 8 3 10 1 6 -1 14 -1 -1 4 7 13 -1 -1 -1 -1 -1 -1 -1 10 | 8 11 | Sample Output : 12 | 3 */ 13 | 14 | public class NodesGreaterThanX { 15 | 16 | /* 17 | * Binary Tree Node class 18 | * 19 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 20 | * right; 21 | * 22 | * public BinaryTreeNode(T data) { this.data = data; } } 23 | */ 24 | 25 | public static int numNodesGreaterX(BinaryTreeNode root, int x) { 26 | /* 27 | * Your class should be named Solution Don't write main(). Don't read input, it 28 | * is passed as function argument. Return output and don't print it. Taking 29 | * input and printing output is handled automatically. 30 | */ 31 | if (root == null) 32 | return 0; 33 | 34 | if (root.data > x) { 35 | return 1 + numNodesGreaterX(root.left, x) + numNodesGreaterX(root.right, x); 36 | } else { 37 | return numNodesGreaterX(root.left, x) + numNodesGreaterX(root.right, x); 38 | } 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/PostOrderTraversal.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree, print the postorder traversal of given tree. 2 | Post-order traversal is: LeftChild RightChild Root 3 | Input format : 4 | Elements in level order form (separated by space) 5 | (If any node does not have left or right child, take -1 in its place) 6 | Output Format : 7 | Post-order traversal, elements separated by space 8 | Sample Input : 9 | 8 3 10 1 6 -1 14 -1 -1 4 7 13 -1 -1 -1 -1 -1 -1 -1 10 | Sample Output : 11 | 1 4 7 6 3 13 14 10 8 */ 12 | 13 | public class PostOrderTraversal { 14 | 15 | /* 16 | * Binary Tree Node class 17 | * 18 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 19 | * right; 20 | * 21 | * public BinaryTreeNode(T data) { this.data = data; } } 22 | */ 23 | public static void postOrder(BinaryTreeNode root) { 24 | /* 25 | * Your class should be named Solution Don't write main(). Don't read input, it 26 | * is passed as function argument. Print output and don't return it. Taking 27 | * input is handled automatically. 28 | */ 29 | if (root == null) 30 | return; 31 | postOrder(root.left); 32 | postOrder(root.right); 33 | System.out.print(root.data + " "); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/PreOrderTraversal.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree, print the preorder traversal of given tree. 2 | Pre-order traversal is: Root LeftChild RightChild 3 | Input format : 4 | Elements in level order form (separated by space) 5 | (If any node does not have left or right child, take -1 in its place) 6 | Output Format : 7 | Pre-order traversal, elements separated by space 8 | Sample Input : 9 | 8 3 10 1 6 -1 14 -1 -1 4 7 13 -1 -1 -1 -1 -1 -1 -1 10 | Sample Output : 11 | 8 3 1 6 4 7 10 14 13 */ 12 | 13 | public class PreOrderTraversal { 14 | 15 | /* 16 | * Binary Tree Node class 17 | * 18 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 19 | * right; 20 | * 21 | * public BinaryTreeNode(T data) { this.data = data; } } 22 | */ 23 | public static void preOrder(BinaryTreeNode root) { 24 | /* 25 | * Your class should be named Solution Don't write main(). Don't read input, it 26 | * is passed as function argument. Print output and don't return it. Taking 27 | * input is handled automatically. 28 | */ 29 | if (root == null) 30 | return; 31 | 32 | System.out.print(root.data + " "); 33 | preOrder(root.left); 34 | preOrder(root.right); 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - I/SumOfNodes.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree, find and return the sum of all nodes. 2 | Input format : 3 | 4 | Elements in level order form (separated by space). If any node does not have left or right child, take -1 in its place. 5 | 6 | Sample Input : 7 | 5 6 10 2 3 -1 -1 -1 -1 -1 9 -1 -1 8 | Sample Output : 9 | 35 */ 10 | 11 | public class SumOfNodes { 12 | 13 | /* 14 | * Binary Tree Node class 15 | * 16 | * class BinaryTreeNode { T data; BinaryTreeNode left; BinaryTreeNode 17 | * right; 18 | * 19 | * public BinaryTreeNode(T data) { this.data = data; } } 20 | */ 21 | 22 | public static int sum(BinaryTreeNode root) { 23 | 24 | // Write your code herei 25 | if (root == null) 26 | return 0; 27 | int smallSum = sum(root.left) + sum(root.right); 28 | return smallSum + root.data; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - II/Assignment/PathSumRootToLeaf.java: -------------------------------------------------------------------------------- 1 | /* Given a binary tree and a number k, print out all root to leaf paths where the sum of all nodes value is same as the given number k. 2 | Input format : 3 | 4 | Line 1 : Elements in level order form (separated by space) 5 | 6 | (If any node does not have left or right child, take -1 in its place) 7 | 8 | Line 2 : k 9 | 10 | Output format : Print each path in new line, elements separated by space 11 | 12 | Sample Input 1 : 13 | 5 6 7 2 3 -1 1 -1 -1 -1 9 -1 -1 -1 -1 14 | 13 15 | Sample Output 1 : 16 | 5 6 2 17 | 5 7 1 */ 18 | 19 | 20 | public class PathSumRootToLeaf { 21 | 22 | /* Binary Tree Node class 23 | * 24 | * class BinaryTreeNode { 25 | T data; 26 | BinaryTreeNode left; 27 | BinaryTreeNode right; 28 | 29 | public BinaryTreeNode(T data) { 30 | this.data = data; 31 | } 32 | } 33 | */ 34 | 35 | public static void rootToLeafPathsSumToK(BinaryTreeNode root, int k) { 36 | // Write your code here 37 | printPath(root, k , ""); 38 | 39 | } 40 | 41 | private static void printPath(BinaryTreeNode root, int k, String path){ 42 | if(root == null) 43 | return; 44 | 45 | String num = root.data + ""; 46 | path = path + num + " "; 47 | 48 | if(k-root.data == 0) 49 | System.out.println(path.trim()); 50 | printPath(root.left, k-root.data, path); 51 | printPath(root.right, k-root.data, path); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Data Structures in Java/Binary Trees - II/Inorder PreOrder PostOrder.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Binary Trees - II/Inorder PreOrder PostOrder.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/1. Time Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/1. Time Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/10. Rehashing.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/10. Rehashing.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/2. Return type.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/2. Return type.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/3. Hashmap Function.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/3. Hashmap Function.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/4. Hash code.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/4. Hash code.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/5. Hash function.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/5. Hash function.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/6. Hashing 1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/6. Hashing 1.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/7. Hashing 2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/7. Hashing 2.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/8. Load Factor.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/8. Load Factor.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/9, Time Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Hashmaps/9, Time Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Hashmaps/Assignment/ExtractUniqueCharacters.java: -------------------------------------------------------------------------------- 1 | /* Given a string, you need to remove all the duplicates. That means, the output string should contain each character only once. The respective order of characters should remain same. 2 | Input format : 3 | String S 4 | Output format : 5 | Output String 6 | Constraints : 7 | 0 <= Length of S <= 10^8 8 | Sample Input 1 : 9 | ababacd 10 | Sample Output 1 : 11 | abcd 12 | Sample Input 2 : 13 | abcde 14 | Sample Output 2 : 15 | abcde */ 16 | 17 | import java.util.*; 18 | 19 | public class ExtractUniqueCharacters { 20 | 21 | public static String uniqueChar(String str) { 22 | // Write your code here 23 | HashMap map = new HashMap<>(); 24 | String s = ""; 25 | for (int i = 0; i < str.length(); i++) { 26 | char ch = str.charAt(i); 27 | if (!map.containsKey(ch)) { 28 | s = s + ch; 29 | map.put(ch, 1); 30 | } 31 | } 32 | return s; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/1. Collection class for Dynamic Array.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/1. Collection class for Dynamic Array.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/10. Search in LL.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/10. Search in LL.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/11. Add element at last.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/11. Add element at last.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/12. Insert at 2nd position.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/12. Insert at 2nd position.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/13. Operations in O(1).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/13. Operations in O(1).PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/14. Operations in O(1).PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/14. Operations in O(1).PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/2. Size of Arraylist.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/2. Size of Arraylist.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/3. ArrayList of Integers.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/3. ArrayList of Integers.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/4. Figure out Element.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/4. Figure out Element.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/5. Figure out correct statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/5. Figure out correct statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/6. Linked List use case.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/6. Linked List use case.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/7. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/7. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/8. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/8. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/9. Find output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - I/9. Find output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/Assignment/EliminateDuplicates.java: -------------------------------------------------------------------------------- 1 | /* 2 | You have been given a singly linked list of integers where the elements are sorted in ascending order. Write a function that removes the consecutive duplicate values such that the given list only contains unique elements and returns the head to the updated list. 3 | */ 4 | 5 | /* 6 | 7 | Following is the Node class already written for the Linked List 8 | 9 | class LinkedListNode { 10 | T data; 11 | LinkedListNode next; 12 | 13 | public LinkedListNode(T data) { 14 | this.data = data; 15 | } 16 | } 17 | 18 | */ 19 | 20 | /* Sample Input 1 : 21 | 1 22 | 1 2 3 3 4 3 4 5 4 5 5 7 -1 23 | Sample Output 1 : 24 | 1 2 3 4 3 4 5 4 5 7 25 | Sample Input 2 : 26 | 2 27 | 10 20 30 40 50 -1 28 | 10 10 10 10 -1 29 | Sample Output 2 : 30 | 10 20 30 40 50 31 | 10 */ 32 | 33 | public class EliminateDuplicates { 34 | public static LinkedListNode removeDuplicates(LinkedListNode head) { 35 | // Your code goes here 36 | LinkedListNode curr = head; 37 | while (curr != null && curr.next != null) { 38 | 39 | if (curr.data.equals(curr.next.data)) { 40 | curr.next = curr.next.next; 41 | } else { 42 | curr = curr.next; 43 | } 44 | } 45 | return head; 46 | } 47 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/Assignment/FindNodeInLInkedList.java: -------------------------------------------------------------------------------- 1 | /* You have been given a singly linked list of integers. Write a function that returns the index/position of an integer data denoted by 'N' (if it exists). Return -1 otherwise. 2 | Note : 3 | Assume that the Indexing for the singly linked list always starts from 0. */ 4 | 5 | /* 6 | 7 | Following is the Node class already written for the Linked List 8 | 9 | class LinkedListNode { 10 | T data; 11 | LinkedListNode next; 12 | 13 | public LinkedListNode(T data) { 14 | this.data = data; 15 | } 16 | } 17 | 18 | */ 19 | 20 | public class Solution { 21 | 22 | public static int findNode(LinkedListNode head, int n) { 23 | // Your code goes here 24 | if (head == null) 25 | return -1; 26 | int pos = 0; 27 | while (head != null) { 28 | if (head.data == n) 29 | return pos; 30 | head = head.next; 31 | pos++; 32 | } 33 | 34 | return -1; 35 | } 36 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/Assignment/PrintReversedLinkedList.java: -------------------------------------------------------------------------------- 1 | /* You have been given a singly linked list of integers. Write a function to print the list in a reverse order. 2 | To explain it further, you need to start printing the data from the tail and move towards the head of the list, printing the head data at the end. 3 | Note : 4 | You can’t change any of the pointers in the linked list, just print it in the reverse order. */ 5 | 6 | /* 7 | Following is the Node class already written for the Linked List 8 | 9 | class LinkedListNode { 10 | T data; 11 | LinkedListNode next; 12 | 13 | public LinkedListNode(T data) { 14 | this.data = data; 15 | } 16 | } 17 | 18 | */ 19 | 20 | public class PrintReversedLinkedList { 21 | public static void printReverse(LinkedListNode root) { 22 | // Your code goes here 23 | if (root == null) 24 | return; 25 | 26 | LinkedListNode prev = null; 27 | LinkedListNode cur = root; 28 | LinkedListNode next = null; 29 | 30 | while (cur != null) { 31 | next = cur.next; 32 | cur.next = prev; 33 | prev = cur; 34 | cur = next; 35 | } 36 | 37 | root = prev; 38 | 39 | while (root != null) { 40 | System.out.print(root.data + " "); 41 | root = root.next; 42 | } 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - I/LengthOfLinkedList.java: -------------------------------------------------------------------------------- 1 | /* For a given singly linked list of integers, find and return its length. Do it using an iterative method. 2 | Input format : 3 | The first line contains an Integer 't' which denotes the number of test cases or queries to be run. Then the test cases follow. 4 | 5 | First and the only line of each test case or query contains elements of the singly linked list separated by a single space. 6 | Remember/Consider : 7 | While specifying the list elements for input, -1 indicates the end of the singly linked list and hence, would never be a list element. 8 | Output format : 9 | For each test case, print the length of the linked list. 10 | 11 | Output for every test case will be printed in a seperate line. 12 | Constraints : 13 | 1 <= t <= 10^2 14 | 0 <= N <= 10^5 15 | Time Limit: 1sec 16 | Sample Input 1 : 17 | 1 18 | 3 4 5 2 6 1 9 -1 19 | Sample Output 1 : 20 | 7 21 | Sample Input 2 : 22 | 2 23 | 10 76 39 -3 2 9 -23 9 -1 24 | -1 25 | Sample Output 2 : 26 | 8 27 | 0*/ 28 | 29 | public class LengthOfLinkedList { 30 | 31 | public static int length(LinkedListNode head) { 32 | // Your code goes here 33 | int count = 0; 34 | while (head != null) { 35 | head = head.next; 36 | count++; 37 | } 38 | return count; 39 | } 40 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/1. Correct output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/1. Correct output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/2. Correct output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/2. Correct output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/3.Traversal.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/3.Traversal.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/4. Double LL.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/4. Double LL.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/5. Circular LL.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/5. Circular LL.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/6. Time complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/6. Time complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/7. Concat linked list.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/7. Concat linked list.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/8. Circular Double LL.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Linked List - II/8. Circular Double LL.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/Assignment/Find node in linked list using recursion.txt: -------------------------------------------------------------------------------- 1 | Given a linked list and an integer n you need to find and return index where n is present in the LL. Do this recursively. 2 | Return -1 if n is not present in the LL. 3 | Indexing of nodes starts from 0. 4 | Input format : 5 | Line 1 : Linked list elements (separated by space and terminated by -1) 6 | Line 2 : Integer n 7 | Output format : 8 | Index 9 | Sample Input 1 : 10 | 3 4 5 2 6 1 9 -1 11 | 5 12 | Sample Output 1 : 13 | 2 14 | Sample Input 2 : 15 | 3 4 5 2 6 1 9 -1 16 | 6 17 | Sample Output 2 : 18 | 4 19 | 20 | 21 | public class Solution { 22 | public static int indexOfNRec(LinkedListNode head, int n) { 23 | /* Your class should be named Solution 24 | * Don't write main(). 25 | * Don't read input, it is passed as function argument. 26 | * Return output and don't print it. 27 | * Taking input and printing output is handled automatically. 28 | */ 29 | if(head == null) 30 | return -1; 31 | if(head.data == n) 32 | return 0; 33 | int smallAns = indexOfNRec(head.next, n); 34 | if(smallAns == -1) 35 | return -1; 36 | else 37 | return 1 + smallAns; 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/Assignment/Swap two nodes of linked list.txt: -------------------------------------------------------------------------------- 1 | Given a linked list, i & j, swap the nodes that are present at i & j position in the LL. You need to swap the entire nodes, not just the data. 2 | Indexing starts from 0. You don't need to print the elements, just swap and return the head of updated LL. 3 | Assume i & j given will be within limits. And i can be greater than j also. 4 | Input format : 5 | 6 | Line 1 : Linked list elements (separated by space and terminated by -1) 7 | 8 | Line 2 : i and j (separated by space) 9 | 10 | Sample Input 1 : 11 | 3 4 5 2 6 1 9 -1 12 | 3 4 13 | Sample Output 1 : 14 | 3 4 5 6 2 1 9 15 | Sample Input 2 : 16 | 3 4 5 2 6 1 9 -1 17 | 2 4 18 | Sample Output 2 : 19 | 3 4 6 2 5 1 9 20 | 21 | 22 | public class Solution { 23 | public static LinkedListNode swap_nodes(LinkedListNode head,int I,int J){ 24 | 25 | LinkedListNode prev1=null,curr1=head,curr2=head,prev2=null; 26 | 27 | for(int i=1;i<=I;i++){ 28 | prev1=curr1; 29 | curr1=curr1.next; 30 | } 31 | for(int i=1;i<=J;i++){ 32 | prev2=curr2; 33 | curr2=curr2.next; 34 | } 35 | if(prev1==null){ 36 | head=curr2; 37 | } 38 | else{ 39 | prev1.next=curr2; 40 | } 41 | 42 | LinkedListNode temp=curr2.next; 43 | if(prev2!=curr1) 44 | curr2.next=curr1.next; 45 | else 46 | curr2.next=curr1; 47 | if(prev2==null){ 48 | head=curr1; 49 | } 50 | else{ 51 | prev2.next=curr1; 52 | } 53 | curr1.next=temp; 54 | return head; 55 | 56 | 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/Delete Node Recursively.txt: -------------------------------------------------------------------------------- 1 | Given a linked list and a position i, delete the node of ith position from Linked List recursively. 2 | If position i is greater than length of LL, then you should return the same LL without any change. 3 | Indexing starts from 0. You don't need to print the elements, just delete the node and return the head of updated LL. 4 | Input format : 5 | Line 1 : Linked list elements (separated by space and terminated by -1) 6 | Line 2 : Integer i (position) 7 | Output format : 8 | Updated LL elements (separated by space) 9 | Sample Input 1 : 10 | 3 4 5 2 6 1 9 -1 11 | 3 12 | Sample Output 1 : 13 | 3 4 5 6 1 9 14 | Sample Input 2 : 15 | 3 4 5 2 6 1 9 -1 16 | 0 17 | Sample Output 2 : 18 | 4 5 2 6 1 9 19 | 20 | 21 | public class Solution { 22 | 23 | public static LinkedListNode deleteIthNodeRec(LinkedListNode head, int pos){ 24 | /* Your class should be named Solution 25 | * Don't write main(). 26 | * Don't read input, it is passed as function argument. 27 | * Return output and don't print it. 28 | * Taking input and printing output is handled automatically. 29 | */ 30 | if (head == null && pos >= 0) 31 | return head; 32 | if (pos == 0) 33 | return head.next; 34 | else { 35 | LinkedListNode smallerHead = deleteIthNodeRec(head.next, pos - 1); 36 | head.next = smallerHead; 37 | return head; 38 | } 39 | 40 | } 41 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/Mid point of linked list.txt: -------------------------------------------------------------------------------- 1 | Given a linked list, find and return the midpoint. 2 | If the length of linked list is even, return the first mid point. 3 | Input format : Linked list elements (separated by space and terminated by -1)` 4 | 5 | Sample Input 1 : 6 | 1 2 3 4 5 -1 7 | Sample Output 1 : 8 | 3 9 | Sample Input 2 : 10 | 1 2 3 4 -1 11 | Sample Output 2 : 12 | 2 13 | 14 | public class Solution { 15 | public static int printMiddel(LinkedListNode head) { 16 | if (head == null || head.next == null) 17 | return head.data; 18 | LinkedListNode dummy = new LinkedListNode(0); 19 | dummy.next = head; 20 | LinkedListNode slow = dummy; 21 | LinkedListNode fast = dummy; 22 | while (fast != null && fast.next != null) { 23 | fast = fast.next.next; 24 | slow = slow.next; 25 | } 26 | return slow.data; 27 | } 28 | } -------------------------------------------------------------------------------- /Data Structures in Java/Linked List - II/Reverse Linked List recursively.txt: -------------------------------------------------------------------------------- 1 | Given a linked list, reverse it using recursion. 2 | You don't need to print the elements, just reverse the LL duplicates and return the head of updated LL. 3 | Input format : Linked list elements (separated by space and terminated by -1)` 4 | 5 | Sample Input 1 : 6 | 1 2 3 4 5 -1 7 | Sample Output 1 : 8 | 5 4 3 2 1 9 | 10 | 11 | public class Solution { 12 | 13 | public static LinkedListNode reverse_R(LinkedListNode head) { 14 | if(head == null || head.next == null) 15 | return head; 16 | 17 | LinkedListNode smallHead = reverse_R(head.next); 18 | head.next.next = head; 19 | head.next = null; 20 | return smallHead; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/1. Correct Statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/1. Correct Statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/10. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/10. Fill the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/11. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/11. Fill the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/12. Keyword.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/12. Keyword.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/13. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/13. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/14. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/14. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/15. Final Keyword.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/15. Final Keyword.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/16. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/16. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/17. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/17. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/18. Find the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/18. Find the error.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/19. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/19. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/2. Object Creation.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/2. Object Creation.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/20. Find the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/20. Find the error.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/3. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/3. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/4. Find the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/4. Find the error.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/5. Possible Output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/5. Possible Output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/6. Access Modifiers.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/6. Access Modifiers.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/7. Check for error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/7. Check for error.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/8. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/8. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - I/9. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - I/9. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/1. OOPS components.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/1. OOPS components.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/10. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/10. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/11. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/11. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/12. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/12. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/13. Correct option.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/13. Correct option.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/14. Correct option.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/14. Correct option.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/15. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/15. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/16. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/16. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/17, What it the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/17, What it the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/18. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/18. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/19. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/19. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/2. Correct Statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/2. Correct Statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/20. Correct statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/20. Correct statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/21. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/21. Fill the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/22. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/22. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/23. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/23. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/24. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/24. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/25. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/25. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/26, What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/26, What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/27. Valid Statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/27. Valid Statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/3. Keyword.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/3. Keyword.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/4. Properties of a class.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/4. Properties of a class.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/5. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/5. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/6. Properties of class.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/6. Properties of class.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/7. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/7. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/8. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/8. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/9. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/9. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/OOPS - II/OOPs notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/OOPS - II/OOPs notes.pdf -------------------------------------------------------------------------------- /Data Structures in Java/Queue/1. Queue.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/1. Queue.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/10. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/10. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/11. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/11. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/12. Queue to stack.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/12. Queue to stack.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/2. Correct Order.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/2. Correct Order.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/3. Function.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/3. Function.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/4 Queue Implementation.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/4 Queue Implementation.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/5. Insert Element.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/5. Insert Element.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/6. Size of Circular Queue.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/6. Size of Circular Queue.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/7. Time Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/7. Time Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/8. LL queue.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/8. LL queue.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/9. Stack and Queue.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Queue/9. Stack and Queue.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Queue/Assignment/ReverseKElements.class: -------------------------------------------------------------------------------- 1 | /* Given a queue and an integer k, reverse first k elements. Return the updated queue. 2 | Do the problem in O(n) complexity. 3 | Input Format : 4 | Line 1 : Integer N, Size of Queue 5 | Line 2 : Queue Elements (separated by space) 6 | Line 3 : Integer k 7 | Output Format: 8 | Updated Queue elements 9 | Contraints : 10 | 1<= N <=10000 11 | Sample Input 1: 12 | 5 13 | 1 2 3 4 5 14 | 3 15 | Sample Output 1: 16 | 3 2 1 4 5 17 | Sample Input 2: 18 | 7 19 | 3 4 2 5 6 7 8 20 | 7 21 | Sample Output 2: 22 | 8 7 6 5 2 4 3 */ 23 | 24 | 25 | import java.util.*; 26 | public class Solution{ 27 | 28 | public static Queue reverseKElements(Queue input,int k){ 29 | /* Your class should be named Solution 30 | * Don't write main(). 31 | * Don't read input, it is passed as function argument. 32 | * Return output and don't print it. 33 | * Taking input and printing output is handled automatically. 34 | */ 35 | Stack stack = new Stack<>(); 36 | while(stack.size() < k) 37 | stack.push(input.poll()); 38 | 39 | //Queue queue = new LinkedList<>(); 40 | //while(!input.isEmpty()) 41 | // queue.add(input.poll()); 42 | 43 | while(!stack.isEmpty()) 44 | input.add(stack.pop()); 45 | 46 | for(int i=0; i { 17 | 18 | public int size(); 19 | 20 | public boolean isEmpty(); 21 | 22 | public T front(); 23 | 24 | public void enqueue(T element); 25 | 26 | public T dequeue(); 27 | } 28 | 29 | **********************************/ 30 | 31 | 32 | import java.util.*; 33 | public class Solution { 34 | 35 | public static void reverseQueue(Queue q) { 36 | Stack stack = new Stack<>(); 37 | while(!q.isEmpty()) 38 | stack.push(q.dequeue()); 39 | 40 | while(!stack.isEmpty()) 41 | q.enqueue(stack.pop()); 42 | 43 | System.out.print(q.dequeue() + " "); 44 | } 45 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/1. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Recursion - I/1. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/2. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Recursion - I/2. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/3. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Recursion - I/3. What is the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/CalculatePower.java: -------------------------------------------------------------------------------- 1 | /* Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to return the answer. 2 | Do this recursively. 3 | Input format : 4 | Two integers x and n (separated by space) 5 | Output Format : 6 | x^n (i.e. x raise to the power n) 7 | Constraints : 8 | 1 <= x <= 30 9 | 0 <= n <= 30 10 | Sample Input 1 : 11 | 3 4 12 | Sample Output 1 : 13 | 81 14 | Sample Input 2 : 15 | 2 5 16 | Sample Output 2 : 17 | 32 */ 18 | 19 | public class Solution { 20 | 21 | public static int power(int x, int n) { 22 | /* 23 | * Your class should be named Solution Don't write main(). Don't read input, it 24 | * is passed as function argument. Return output and don't print it. Taking 25 | * input and printing output is handled automatically. 26 | */ 27 | return calcPower(x, n); 28 | } 29 | 30 | public static int calcPower(int x, int n) { 31 | if (n == 0) 32 | return 1; 33 | int smallOutput = calcPower(x, n - 1); 34 | int output = smallOutput * x; 35 | return output; 36 | } 37 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/CheckNumberInArray.java: -------------------------------------------------------------------------------- 1 | /* Given an array of length N and an integer x, you need to find if x is present in the array or not. Return true or false. 2 | Do this recursively. 3 | Input Format : 4 | Line 1 : An Integer N i.e. size of array 5 | Line 2 : N integers which are elements of the array, separated by spaces 6 | Line 3 : Integer x 7 | Output Format : 8 | 'true' or 'false' 9 | Constraints : 10 | 1 <= N <= 10^3 11 | Sample Input 1 : 12 | 3 13 | 9 8 10 14 | 8 15 | Sample Output 1 : 16 | true 17 | Sample Input 2 : 18 | 3 19 | 9 8 10 20 | 2 21 | Sample Output 2 : 22 | false */ 23 | 24 | public class CheckNumberInArray { 25 | 26 | public static boolean checkNumber(int input[], int x) { 27 | /* 28 | * Your class should be named Solution Don't write main(). Don't read input, it 29 | * is passed as function argument. Return output and don't print it. Taking 30 | * input and printing output is handled automatically. 31 | */ 32 | return find(input, input.length, x); 33 | } 34 | 35 | public static boolean find(int input[], int n, int x) { 36 | if (n <= 0) 37 | return false; 38 | if (input[n - 1] == x) 39 | return true; 40 | else 41 | return find(input, n - 1, x); 42 | } 43 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/FirstIndex.java: -------------------------------------------------------------------------------- 1 | /* Given an array of length N and an integer x, you need to find and return the first index of integer x present in the array. Return -1 if it is not present in the array. 2 | First index means, the index of first occurrence of x in the input array. 3 | Do this recursively. Indexing in the array starts from 0. 4 | Input Format : 5 | Line 1 : An Integer N i.e. size of array 6 | Line 2 : N integers which are elements of the array, separated by spaces 7 | Line 3 : Integer x 8 | Output Format : 9 | first index or -1 10 | Constraints : 11 | 1 <= N <= 10^3 12 | Sample Input : 13 | 4 14 | 9 8 10 8 15 | 8 16 | Sample Output : 17 | 1 */ 18 | 19 | public class FristIndex { 20 | 21 | public static int firstIndex(int input[], int x) { 22 | /* 23 | * Your class should be named Solution Don't write main(). Don't read input, it 24 | * is passed as function argument. Return output and don't print it. Taking 25 | * input and printing output is handled automatically. 26 | */ 27 | return findFirst(input, 0, x); 28 | 29 | } 30 | 31 | public static int findFirst(int input[], int n, int x) { 32 | if (n == input.length) 33 | return -1; 34 | 35 | if (input[n] == x) 36 | return n; 37 | return findFirst(input, n + 1, x); 38 | } 39 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/FirstNNaturalNumbers.java: -------------------------------------------------------------------------------- 1 | /* Given is the code to print numbers from 1 to n in increasing order recursively. But it contains few bugs that you need to rectify such that all the test cases pass. 2 | Input Format : 3 | Integer n 4 | Output Format : 5 | Numbers from 1 to n (separated by space) 6 | Constraints : 7 | 1 <= n <= 10000 8 | Sample Input 1 : 9 | 6 10 | Sample Output 1 : 11 | 1 2 3 4 5 6 12 | Sample Input 2 : 13 | 4 14 | Sample Output 2 : 15 | 1 2 3 4 */ 16 | 17 | 18 | 19 | public class Solution { 20 | 21 | public static void print(int n){ 22 | if(n == 0){ 23 | //System.out.print(n + " "); 24 | return; 25 | } 26 | print(n - 1); 27 | System.out.print(n+" "); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/LastIndex.java: -------------------------------------------------------------------------------- 1 | /* Given an array of length N and an integer x, you need to find and return the last index of integer x present in the array. Return -1 if it is not present in the array. 2 | Last index means - if x is present multiple times in the array, return the index at which x comes last in the array. 3 | You should start traversing your array from 0, not from (N - 1). 4 | Do this recursively. Indexing in the array starts from 0. 5 | Input Format : 6 | Line 1 : An Integer N i.e. size of array 7 | Line 2 : N integers which are elements of the array, separated by spaces 8 | Line 3 : Integer x 9 | Output Format : 10 | last index or -1 11 | Constraints : 12 | 1 <= N <= 10^3 13 | Sample Input : 14 | 4 15 | 9 8 10 8 16 | 8 17 | Sample Output : 18 | 3 */ 19 | 20 | 21 | 22 | 23 | public class Solution { 24 | 25 | public static int lastIndex(int input[], int x) { 26 | 27 | return findLast(input, input.length-1, x); 28 | } 29 | 30 | public static int findLast(int input[], int n, int x){ 31 | if(n == 0) 32 | return -1; 33 | if(x == input[n]) 34 | return n; 35 | return findLast(input, n-1, x); 36 | } 37 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/NumberOfDigits.java: -------------------------------------------------------------------------------- 1 | /* Given the code to find out and return the number of digits present in a number recursively. But it contains few bugs, that you need to rectify such that all the test cases should pass. 2 | Input Format : 3 | Integer n 4 | Output Format : 5 | Count of digits 6 | Constraints : 7 | 1 <= n <= 10^6 8 | Sample Input 1 : 9 | 156 10 | Sample Output 1 : 11 | 3 12 | Sample Input 2 : 13 | 7 14 | Sample Output 2 : 15 | 1 */ 16 | 17 | public class NumberOfDigits { 18 | 19 | public static int count(int n) { 20 | if (n == 0) { 21 | return 0; 22 | } 23 | int smallAns = count(n / 10); 24 | return smallAns + 1; 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/Recursion Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Recursion - I/Recursion Notes.pdf -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - I/SumOfArray.java: -------------------------------------------------------------------------------- 1 | /* Given an array of length N, you need to find and return the sum of all elements of the array. 2 | Do this recursively. 3 | Input Format : 4 | Line 1 : An Integer N i.e. size of array 5 | Line 2 : N integers which are elements of the array, separated by spaces 6 | Output Format : 7 | Sum 8 | Constraints : 9 | 1 <= N <= 10^3 10 | Sample Input 1 : 11 | 3 12 | 9 8 9 13 | Sample Output 1 : 14 | 26 15 | Sample Input 2 : 16 | 3 17 | 4 2 1 18 | Sample Output 2 : 19 | 7 */ 20 | 21 | public class SumOfArray { 22 | 23 | public static int sum(int input[]) { 24 | return calcSum(input, input.length); 25 | } 26 | 27 | public static int calcSum(int input[], int n) { 28 | if (n <= 0) 29 | return 0; 30 | int smallSum = calcSum(input, n - 1); 31 | int output = input[n - 1] + smallSum; 32 | return output; 33 | } 34 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - II/RemoveDuplicates.java: -------------------------------------------------------------------------------- 1 | /* Given a string S, remove consecutive duplicates from it recursively. 2 | Input Format : 3 | String S 4 | Output Format : 5 | Output string 6 | Constraints : 7 | 1 <= |S| <= 10^3 8 | where |S| represents the length of string 9 | Sample Input 1 : 10 | aabccba 11 | Sample Output 1 : 12 | abcba 13 | Sample Input 2 : 14 | xxxyyyzwwzzz 15 | Sample Output 2 : 16 | xyzwz */ 17 | 18 | public class RemoveDuplicates { 19 | 20 | public static String removeConsecutiveDuplicates(String s) { 21 | // Write your code here 22 | if (s.length() <= 1) 23 | return s; 24 | String smallOutput = removeConsecutiveDuplicates(s.substring(1)); 25 | if (s.charAt(0) == smallOutput.charAt(0)) 26 | return smallOutput; 27 | else 28 | return s.charAt(0) + smallOutput; 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - II/RemoveX.java: -------------------------------------------------------------------------------- 1 | /* Remove X 2 | Send Feedback 3 | Given a string, compute recursively a new string where all 'x' chars have been removed. 4 | Input format : 5 | String S 6 | Output format : 7 | Modified String 8 | Constraints : 9 | 1 <= |S| <= 10^3 10 | where |S| represents the length of string S. 11 | Sample Input 1 : 12 | xaxb 13 | Sample Output 1: 14 | ab 15 | Sample Input 2 : 16 | abc 17 | Sample Output 2: 18 | abc 19 | Sample Input 3 : 20 | xx 21 | Sample Output 3: */ 22 | 23 | public class REmoveX { 24 | 25 | // Return the changed string 26 | public static String removeX(String input) { 27 | // Write your code here 28 | if (input.length() == 0) 29 | return input; 30 | String smallOutput = removeX(input.substring(1)); 31 | if (input.charAt(0) == 'x') 32 | return smallOutput; 33 | else 34 | return input.charAt(0) + smallOutput; 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion - II/TowerOfHanoi.java: -------------------------------------------------------------------------------- 1 | /* Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move all disks from source rod to destination rod using third rod (say auxiliary). The rules are : 2 | 1) Only one disk can be moved at a time. 3 | 2) A disk can be moved only if it is on the top of a rod. 4 | 3) No disk can be placed on the top of a smaller disk. 5 | Print the steps required to move n disks from source rod to destination rod. 6 | Source Rod is named as 'a', auxiliary rod as 'b' and destination rod as 'c'. 7 | Input Format : 8 | Integer n 9 | Output Format : 10 | Steps in different lines (in one line print source and destination rod name separated by space) 11 | Constraints : 12 | 0 <= n <= 20 13 | Sample Input 1 : 14 | 2 15 | Sample Output 1 : 16 | a b 17 | a c 18 | b c 19 | Sample Input 2 : 20 | 3 21 | Sample Output 2 : 22 | a c 23 | a b 24 | c b 25 | a c 26 | b a 27 | b c 28 | a c */ 29 | 30 | public class TowerOfHanoi { 31 | 32 | static void towerOfHanoi(int n, char from_rod, char aux_rod, char to_rod) { 33 | if (n == 0) 34 | return; 35 | if (n == 1) { 36 | System.out.println(from_rod + " " + to_rod); 37 | return; 38 | } 39 | towerOfHanoi(n - 1, from_rod, to_rod, aux_rod); 40 | System.out.println(from_rod + " " + to_rod); 41 | towerOfHanoi(n - 1, aux_rod, from_rod, to_rod); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/CheckAB.java: -------------------------------------------------------------------------------- 1 | /* Suppose you have a string, S, made up of only 'a's and 'b's. Write a recursive function that checks if the string was generated using the following rules: 2 | a. The string begins with an 'a' 3 | b. Each 'a' is followed by nothing or an 'a' or "bb" 4 | c. Each "bb" is followed by nothing or an 'a' 5 | If all the rules are followed by the given string, return true otherwise return false. 6 | Input format : 7 | String S 8 | Output format : 9 | 'true' or 'false' 10 | Constraints : 11 | 0 <= |S| <= 1000 12 | where |S| represents length of string S. 13 | Sample Input 1 : 14 | abb 15 | Sample Output 1 : 16 | true 17 | Sample Input 2 : 18 | abababa 19 | Sample Output 2 : 20 | false */ 21 | 22 | public class CheckAB { 23 | 24 | public static boolean checkAB(String input) { 25 | // Write your code here 26 | if (input.length() == 0) { 27 | return true; 28 | } 29 | 30 | if (input.charAt(0) == 'a') { 31 | if (input.substring(1).length() > 1 && input.substring(1, 3).equals("bb")) { 32 | return checkAB(input.substring(3)); 33 | } else { 34 | return checkAB(input.substring(1)); 35 | } 36 | } 37 | return false; 38 | } 39 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/CheckPalindrome.java: -------------------------------------------------------------------------------- 1 | /* Check whether a given String S is a palindrome using recursion. Return true or false. 2 | Input Format : 3 | String S 4 | Output Format : 5 | 'true' or 'false' 6 | Constraints : 7 | 0 <= |S| <= 1000 8 | where |S| represents length of string S. 9 | Sample Input 1 : 10 | racecar 11 | Sample Output 1: 12 | true 13 | Sample Input 2 : 14 | ninja 15 | Sample Output 2: 16 | false */ 17 | 18 | 19 | 20 | public class solution { 21 | 22 | public static boolean isStringPalindrome(String input) { 23 | // Write your code here 24 | return input.equals(palindrome(input)); 25 | } 26 | 27 | public static String palindrome(String s){ 28 | if(s.length() == 0) 29 | return s; 30 | String smallOutput = palindrome(s.substring(1)); 31 | return smallOutput + s.charAt(0); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/CountZeros.java: -------------------------------------------------------------------------------- 1 | /* Given an integer N, count and return the number of zeros that are present in the given integer using recursion. 2 | Input Format : 3 | Integer N 4 | Output Format : 5 | Number of zeros in N 6 | Constraints : 7 | 0 <= N <= 10^9 8 | Sample Input 1 : 9 | 10204 10 | Sample Output 1 : 11 | 2 12 | Sample Input 2 : 13 | 708000 14 | Sample Output 2 : 15 | 4 */ 16 | 17 | public class CountZeros { 18 | 19 | public static int countZerosRec(int input) { 20 | // Write your code here 21 | if (input == 0) 22 | return 0; 23 | if (input % 10 == 0) 24 | return 1 + countZerosRec(input / 10); 25 | else 26 | return countZerosRec(input / 10); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/GeometricSum.java: -------------------------------------------------------------------------------- 1 | /* Given k, find the geometric sum i.e. 2 | 1 + 1/2 + 1/4 + 1/8 + ... + 1/(2^k) 3 | using recursion. 4 | Input format : 5 | Integer k 6 | Output format : 7 | Geometric sum 8 | Constraints : 9 | 0 <= k <= 1000 10 | Sample Input 1 : 11 | 3 12 | Sample Output 1 : 13 | 1.875 14 | Sample Input 2 : 15 | 4 16 | Sample Output 2 : 17 | 1.93750 */ 18 | 19 | import java.lang.Math; 20 | 21 | public class GeometricSum { 22 | 23 | public static double findGeometricSum(int k) { 24 | // Write your code here 25 | if (k == 0) 26 | return 1; 27 | 28 | double smallOutput = findGeometricSum(k - 1); 29 | return smallOutput + 1 / (double) Math.pow(2, k); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/Multiplication.java: -------------------------------------------------------------------------------- 1 | /* Given two integers M & N, calculate and return their multiplication using recursion. You can only use subtraction and addition for your calculation. No other operators are allowed. 2 | Input format : 3 | Line 1 : Integer M 4 | Line 2 : Integer N 5 | Output format : 6 | M x N 7 | Constraints : 8 | 0 <= M <= 1000 9 | 0 <= N <= 1000 10 | Sample Input 1 : 11 | 3 12 | 5 13 | Sample Output 1 : 14 | 15 15 | Sample Input 2 : 16 | 4 17 | 0 18 | Sample Output 2 : 19 | 0 */ 20 | 21 | public class Multiplication { 22 | 23 | public static int multiplyTwoIntegers(int m, int n) { 24 | // Write your code here 25 | if (n == 0) 26 | return 0; 27 | if (n == 1) 28 | return m; 29 | return m + multiplyTwoIntegers(m, n - 1); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/PairStar.java: -------------------------------------------------------------------------------- 1 | /* Given a string S, compute recursively a new string where identical chars that are adjacent in the original string are separated from each other by a "*". 2 | Input format : 3 | String S 4 | Output format : 5 | Modified string 6 | Constraints : 7 | 0 <= |S| <= 1000 8 | where |S| represents length of string S. 9 | Sample Input 1 : 10 | hello 11 | Sample Output 1: 12 | hel*lo 13 | Sample Input 2 : 14 | aaaa 15 | Sample Output 2 : 16 | a*a*a*a */ 17 | 18 | public class PairStar { 19 | 20 | // Return the updated string 21 | public static String addStars(String s) { 22 | // Write your code here 23 | if (s.length() == 1) 24 | return s; 25 | String smallOutput = addStars(s.substring(1)); 26 | if (s.charAt(0) == smallOutput.charAt(0)) 27 | return s.charAt(0) + "*" + smallOutput; 28 | else 29 | return s.charAt(0) + smallOutput; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/StairCase.java: -------------------------------------------------------------------------------- 1 | /* A child is running up a staircase with N steps, and can hop either 1 step, 2 steps or 3 steps at a time. Implement a method to count how many possible ways the child can run up to the stairs. You need to return number of possible ways W. 2 | Input format : 3 | Integer N 4 | Output Format : 5 | Integer W 6 | Constraints : 7 | 1 <= N <= 30 8 | Sample Input 1 : 9 | 4 10 | Sample Output 1 : 11 | 7 12 | Sample Input 2 : 13 | 5 14 | Sample Output 2 : 15 | 13 */ 16 | 17 | 18 | 19 | 20 | public class Solution { 21 | 22 | 23 | public static int staircase(int n){ 24 | 25 | /* Your class should be named Solution. 26 | * Don't write main() function. 27 | * Don't read input, it is passed as function argument. 28 | * Return output and don't print it. 29 | * Taking input and printing output is handled automatically. 30 | */ 31 | if(n == 0) 32 | return 0; 33 | 34 | if(n == 1) 35 | return 1; 36 | if(n == 2) 37 | return 2; 38 | if(n == 3) 39 | return 4; 40 | 41 | return staircase(n-1) + staircase(n-2) + staircase(n-3); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/StringToInteger.java: -------------------------------------------------------------------------------- 1 | /* Write a recursive function to convert a given string into the number it represents. That is input will be a numeric string that contains only numbers, you need to convert the string into corresponding integer and return the answer. 2 | Input format : 3 | Numeric string S (string, Eg. "1234") 4 | Output format : 5 | Corresponding integer N (int, Eg. 1234) 6 | Constraints : 7 | 0 <= |S| <= 9 8 | where |S| represents length of string S. 9 | Sample Input 1 : 10 | 1231 11 | Sample Output 1 : 12 | 1231 13 | Sample Input 2 : 14 | 12567 15 | Sample Output 2 : 16 | 12567 */ 17 | 18 | import java.lang.Math; 19 | 20 | public class StringToInteger { 21 | 22 | public static int convertStringToInt(String input) { 23 | // Write your code here 24 | if (input.length() == 1) 25 | return input.charAt(0) - '0'; 26 | 27 | double y = convertStringToInt(input.substring(1)); 28 | double x = input.charAt(0) - '0'; 29 | x = x * (Math.pow(10, input.length() - 1)) + y; 30 | return (int) x; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Data Structures in Java/Recursion Assignment/SumOfDigits.java: -------------------------------------------------------------------------------- 1 | /* Write a recursive function that returns the sum of the digits of a given integer. 2 | Input format : 3 | Integer N 4 | Output format : 5 | Sum of digits of N 6 | Constraints : 7 | 0 <= N <= 10^9 8 | Sample Input 1 : 9 | 12345 10 | Sample Output 1 : 11 | 15 12 | Sample Input 2 : 13 | 9 14 | Sample Output 2 : 15 | 9 */ 16 | 17 | 18 | 19 | public class SumOfDigits { 20 | 21 | public static int sumOfDigits(int input){ 22 | // Write your code here 23 | if(input == 0) 24 | return 0; 25 | int digit = input%10; 26 | int smallOutput = sumOfDigits(input/10); 27 | return digit + smallOutput; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/1. Index problem.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/1. Index problem.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/10. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/10. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/11. Double Stack.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/11. Double Stack.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/12. Time Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/12. Time Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/13. LL Stacks.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/13. LL Stacks.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/14. Time Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/14. Time Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/15. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/15. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/16. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/16. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/17. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/17. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/18. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/18. Predict the output.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/2. Stack.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/2. Stack.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/3. Size of stack.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/3. Size of stack.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/4. Sum of stack.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/4. Sum of stack.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/5. Size Function.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/5. Size Function.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/6. Correct Statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/6. Correct Statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/7. Stack Implementation.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/7. Stack Implementation.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/8. Stack Implementation.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/8. Stack Implementation.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/9. Correct Statement.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Stacks/9. Correct Statement.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Stacks/Assignment/Minimum bracket reversal.txt: -------------------------------------------------------------------------------- 1 | Given a string expression which consists only ‘}’ and ‘{‘. The expression may not be balanced. You need to find the minimum number of bracket reversals which are required to make the expression balanced. 2 | Return -1 if the given expression can't be balanced. 3 | Input Format : 4 | String S 5 | Output Format : 6 | Required count 7 | Sample Input 1 : 8 | {{{ 9 | Sample Output 1 : 10 | -1 11 | Sample Input 2 : 12 | {{{{}} 13 | Sample Output 2 : 14 | 1 15 | 16 | 17 | 18 | import java.util.Stack; 19 | 20 | public class Solution { 21 | 22 | public static int countBracketReversals(String str) { 23 | if(str.length()%2!=0){ 24 | return -1; 25 | } 26 | 27 | 28 | Stack stack = new Stack<>(); 29 | 30 | for(int i=0;i stack = new Stack<>(); 20 | for(int i=0; i stack1, Stack stack2) { 18 | 19 | if(stack1.isEmpty()) { 20 | return ; 21 | } 22 | 23 | int temp = stack1.pop(); 24 | 25 | reverseStack(stack1, stack2); 26 | 27 | while(!stack1.isEmpty() ) { 28 | stack2.push(stack1.pop()); 29 | } 30 | 31 | stack1.push(temp); 32 | 33 | while(!stack2.isEmpty()) { 34 | stack1.push(stack2.pop()); 35 | } 36 | } 37 | 38 | 39 | } -------------------------------------------------------------------------------- /Data Structures in Java/Test 1/1. Recurrence Relation for Tower of Hanoi.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Test 1/1. Recurrence Relation for Tower of Hanoi.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Test 1/2. Complexity of different operations in a sorted array.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Test 1/2. Complexity of different operations in a sorted array.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Test 1/3. Complexity of Recurrence Relation.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Test 1/3. Complexity of Recurrence Relation.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Test 1/DoesSContainT.java: -------------------------------------------------------------------------------- 1 | /* Given two string s and t, write a function to check if s contains all characters of t (in the same order as they are in string t). 2 | Return true or false. 3 | Do it recursively. 4 | E.g. : s = “abchjsgsuohhdhyrikkknddg” contains all characters of t=”coding” in the same order. So function will return true. 5 | Input Format : 6 | Line 1 : String s 7 | Line 2 : String t 8 | Output Format : 9 | true or false 10 | Sample Input 1 : 11 | abchjsgsuohhdhyrikkknddg 12 | coding 13 | Sample Output 1 : 14 | true 15 | Sample Input 2 : 16 | abcde 17 | aeb 18 | Sample Output 2 : 19 | false */ 20 | 21 | public class DoesSContainT { 22 | public static boolean checkSequence(String a, String b) { 23 | /* 24 | * Your class should be named Solution Don't write main(). Don't read input, it 25 | * is passed as function argument. Return output and don't print it. Taking 26 | * input and printing output is handled automatically. 27 | */ 28 | if (b.length() == 0) 29 | return true; 30 | if (a.length() == 0 && b.length() != 0) 31 | return false; 32 | 33 | if (a.charAt(0) == b.charAt(0)) 34 | return checkSequence(a.substring(1), b.substring(1)); 35 | else 36 | return checkSequence(a.substring(1), b); 37 | } 38 | } -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/1. Complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/1. Complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/2. Number of operations.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/2. Number of operations.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/3 Number of operations.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/3 Number of operations.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/4. Time Complexity of Code.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/4. Time Complexity of Code.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/5. Time complexity of code.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/5. Time complexity of code.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/6. Time complexity.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/6. Time complexity.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/7. Time complexity of code.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/7. Time complexity of code.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/8. Time complexity of code.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/8. Time complexity of code.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/9. Merging 2 sorted arrays.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Data Structures in Java/Time Complexity/9. Merging 2 sorted arrays.PNG -------------------------------------------------------------------------------- /Data Structures in Java/Time Complexity/ArrayEquilibrium.java: -------------------------------------------------------------------------------- 1 | /* Find and return the equilibrium index of an array. Equilibrium index of an array is an index i such that the sum of elements at indices less than i is equal to the sum of elements at indices greater than i. 2 | Element at index i is not included in either part. 3 | If more than one equilibrium index is present, you need to return the first one. And return -1 if no equilibrium index is present. 4 | Input format : 5 | Line 1 : Size of input array 6 | Line 2 : Array elements (separated by space) 7 | Constraints: 8 | Time Limit: 1 second 9 | Size of input array lies in the range: [1, 1000000] 10 | Sample Input : 11 | 7 12 | -7 1 5 2 -4 3 0 13 | Sample Output : 14 | 3 */ 15 | 16 | 17 | public class ArrayEquilibrium{ 18 | //arr is the given array in which you need to find the equilibrium index 19 | public static int arrayEquilibrium(int[] arr){ 20 | //write your code here 21 | int suffixSum = 0; 22 | int prefixSum = 0; 23 | for(int i : arr) 24 | suffixSum += i; 25 | for(int i=0; i { 6 | T data; 7 | ArrayList> children; 8 | 9 | TreeNode(T data){ 10 | this.data = data; 11 | children = new ArrayList>(); 12 | } 13 | }*/ 14 | 15 | public static boolean checkIfContainsX(TreeNode root, int x){ 16 | 17 | // Write your code here 18 | if(root == null) 19 | return false; 20 | 21 | //boolean found = false; 22 | if(root.data == x) 23 | return true; 24 | 25 | for(TreeNode child : root.children){ 26 | if(checkIfContainsX(child,x)) 27 | return true; 28 | } 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/CountAllLeafNodes.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | /* TreeNode structure 4 | * 5 | * class TreeNode { 6 | T data; 7 | ArrayList> children; 8 | 9 | TreeNode(T data){ 10 | this.data = data; 11 | children = new ArrayList>(); 12 | } 13 | }*/ 14 | 15 | public static int countLeafNodes(TreeNode root){ 16 | 17 | // Write your code here 18 | if(root == null) 19 | return 0; 20 | 21 | int count = 0; 22 | if(root.children.size() == 0) 23 | count++; 24 | for(TreeNode child : root.children) 25 | count += countLeafNodes(child); 26 | return count; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/HeightOfGenericTree.java: -------------------------------------------------------------------------------- 1 | 2 | public class HeightOfGenericTree { 3 | 4 | /* 5 | * TreeNode structure 6 | * 7 | * class TreeNode { T data; ArrayList> children; 8 | * 9 | * TreeNode(T data){ this.data = data; children = new ArrayList>(); 10 | * } } 11 | */ 12 | 13 | public static int height(TreeNode root) { 14 | if (root == null) 15 | return 0; 16 | 17 | int max = 1; 18 | for (TreeNode child : root.children) { 19 | int childHeight = 1 + height(child); 20 | if (max < childHeight) 21 | max = childHeight; 22 | } 23 | return max; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/NodesGreaterThanX.java: -------------------------------------------------------------------------------- 1 | public class NodesGreaterThanX { 2 | 3 | /* 4 | * TreeNode class 5 | * 6 | * class TreeNode { T data; ArrayList> children; 7 | * 8 | * TreeNode(T data){ this.data = data; children = new ArrayList>(); 9 | * } } 10 | */ 11 | 12 | public static int numNodeGreater(TreeNode root, int x) { 13 | 14 | // Write your code here 15 | if (root == null) 16 | return 0; 17 | 18 | int count = 0; 19 | if (root.data > x) 20 | count++; 21 | for (TreeNode child : root.children) 22 | count += numNodeGreater(child, x); 23 | 24 | return count; 25 | }} 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/NumberOFNodesGreaterThanX.java: -------------------------------------------------------------------------------- 1 | /* Given a tree and an integer x, find and return number of Nodes which are greater than x. 2 | Input format : 3 | Single Line : First Integer denotes x and rest of the elements in level order form separated by space. Order is - 4 | Root_data, n (No_Of_Child_Of_Root), n children, and so on for every element 5 | Output Format : 6 | Count of nodes greater than x 7 | Sample Input 1 : 8 | 35 10 3 20 30 40 2 40 50 0 0 0 0 9 | Sample Output 1 : 10 | 3 11 | Sample Input 2 : 12 | 10 10 3 20 30 40 2 40 50 0 0 0 0 13 | Sample Output 2: 14 | 5 */ 15 | 16 | 17 | public class NumberOfNodesGreaterThanX { 18 | 19 | /* TreeNode class 20 | * 21 | * class TreeNode { 22 | T data; 23 | ArrayList> children; 24 | 25 | TreeNode(T data){ 26 | this.data = data; 27 | children = new ArrayList>(); 28 | } 29 | }*/ 30 | 31 | 32 | public static int numNodeGreater(TreeNode root,int x){ 33 | 34 | // Write your code here 35 | if(root == null) 36 | return 0; 37 | 38 | int count = 0; 39 | if(root.data > x) 40 | { 41 | count++; 42 | } 43 | for(TreeNode node : root.children) 44 | count += numNodeGreater(node, x); 45 | return count; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/PostOrderTraversalGenericTree.java: -------------------------------------------------------------------------------- 1 | 2 | public class PostOrderTraversalGenericTree { 3 | 4 | /* TreeNode structure 5 | * 6 | * class TreeNode { 7 | T data; 8 | ArrayList> children; 9 | 10 | TreeNode(T data){ 11 | this.data = data; 12 | children = new ArrayList>(); 13 | } 14 | }*/ 15 | 16 | public static void postOrder(TreeNode root){ 17 | /* Your class should be named Solution. 18 | * Don't write main() function. 19 | * Don't read input, it is passed as function argument. 20 | * Print output as specified in the question 21 | */ 22 | if(root == null) 23 | return; 24 | 25 | for(TreeNode child : root.children) 26 | postOrder(child); 27 | 28 | System.out.print(root.data+" "); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/ReplaceWithLargerNodesSum.java: -------------------------------------------------------------------------------- 1 | 2 | public class Solution { 3 | 4 | /* Binary Tree Node class 5 | * 6 | * class BinaryTreeNode { 7 | T data; 8 | BinaryTreeNode left; 9 | BinaryTreeNode right; 10 | 11 | public BinaryTreeNode(T data) { 12 | this.data = data; 13 | } 14 | } 15 | */ 16 | 17 | public static int replaceWithLargerNodesSum (BinaryTreeNode root, int sum){ 18 | if(root == null) 19 | return sum; 20 | sum = replaceWithLargerNodesSum(root.right, sum); 21 | sum += root.data; 22 | root.data = sum; 23 | sum = replaceWithLargerNodesSum(root.left, sum); 24 | return sum; 25 | } 26 | 27 | public static void replaceWithLargerNodesSum(BinaryTreeNode root){ 28 | int sum = 0; 29 | replaceWithLargerNodesSum(root, sum); 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Data Structures in Java/Trees/SumOfAllNodes.java: -------------------------------------------------------------------------------- 1 | 2 | public class SumOfAllNodes { 3 | 4 | /* TreeNode structure 5 | * 6 | * class TreeNode { 7 | T data; 8 | ArrayList> children; 9 | 10 | TreeNode(T data){ 11 | this.data = data; 12 | children = new ArrayList>(); 13 | } 14 | }*/ 15 | 16 | 17 | 18 | public static int sumOfAllNode(TreeNode root){ 19 | if(root == null) 20 | return 0; 21 | 22 | int sum = 0; 23 | for(int i=0; i= arr.length) 41 | break; 42 | int temp = arr[i]; 43 | arr[i] = arr[i+1]; 44 | arr[i+1] = temp; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 11 Arrays 2/BinarySearch.java: -------------------------------------------------------------------------------- 1 | 2 | public class BinarySearch { 3 | 4 | public static int binarySearch(int[] arr, int x) { 5 | //Your code goes here 6 | int start = 0; 7 | int end = arr.length-1; 8 | int mid; 9 | while(start <= end){ 10 | mid = start + (end - start)/2; 11 | if(arr[mid] == x) 12 | return mid; 13 | else if(arr[mid] > x){ 14 | end = mid - 1; 15 | } 16 | else{ 17 | start = mid + 1; 18 | } 19 | } 20 | return -1; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 11 Arrays 2/BubbleSort.java: -------------------------------------------------------------------------------- 1 | 2 | public class BubbleSort { 3 | 4 | public static void bubbleSort(int[] arr) { 5 | // Your code goes here 6 | int n = arr.length; 7 | for (int i = 0; i < n - 1; i++) 8 | for (int j = 0; j < n - i - 1; j++) 9 | if (arr[j] > arr[j + 1]) { 10 | int temp = arr[j]; 11 | arr[j] = arr[j + 1]; 12 | arr[j + 1] = temp; 13 | } 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 11 Arrays 2/InsertionSort.java: -------------------------------------------------------------------------------- 1 | 2 | public class InsertionSort { 3 | 4 | public static void insertionSort(int[] arr) { 5 | // Your code goes here 6 | int n = arr.length; 7 | for (int i = 1; i < n; ++i) { 8 | int key = arr[i]; 9 | int j = i - 1; 10 | while (j >= 0 && arr[j] > key) { 11 | arr[j + 1] = arr[j]; 12 | j = j - 1; 13 | } 14 | arr[j + 1] = key; 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 11 Arrays 2/Merge2SortedArrays.java: -------------------------------------------------------------------------------- 1 | 2 | public class Merge2SortedArrays { 3 | 4 | public static int[] merge(int arr1[], int arr2[]) { 5 | //Your code goes here 6 | int n1 = arr1.length; 7 | int n2 = arr2.length; 8 | int[] arr3 = new int[n1+n2]; 9 | int i = 0; 10 | int j = 0; 11 | int k = 0; 12 | while (i max){ 41 | max = currCount; 42 | maxChar = inputString.charAt(i); 43 | } 44 | } 45 | return maxChar; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 12 Stings/Assignment/RemoveCharacter.java: -------------------------------------------------------------------------------- 1 | /* Given a string and a character x. Write a function to remove all occurrences of x character from the given string. 2 | Leave the string as it is, if the given character is not present in the string. 3 | 4 | 5 | Input Format : 6 | Line 1 : String S 7 | Line 2 : Character c 8 | Output Format : 9 | Modified string 10 | Constraints : 11 | 0 <= |S| <= 10^7 12 | where |S| represents the length of string, S. 13 | Sample Input 1: 14 | welcome to coding ninjas 15 | o 16 | Sample Output 1: 17 | welcme t cding ninjas 18 | Sample Input 2: 19 | Think of edge cases before submitting solutions 20 | x 21 | Sample Output 2: 22 | Think of edge cases before submitting solutions */ 23 | 24 | 25 | public class RemoveCharacter { 26 | 27 | public static String removeAllOccurrencesOfChar(String input, char c) { 28 | // Write your code here 29 | int n = input.length(); 30 | String result = ""; 31 | for(int i=0; i= 65 && ch <= 90) 14 | System.out.println(1); 15 | else if(ch >=97 && ch <= 122) 16 | System.out.println(0); 17 | else 18 | System.out.println(-1); 19 | 20 | } 21 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/14. Number of hellos.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/14. Number of hellos.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/15. Number of hello 2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/15. Number of hello 2.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/16. Same output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/16. Same output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/17. Fahrenheit to Celsius Table.txt: -------------------------------------------------------------------------------- 1 | /*Given three values - Start Fahrenheit Value (S), End Fahrenheit value (E) and Step Size (W), you need to convert all Fahrenheit values from Start to End at the gap of W, into their corresponding Celsius values and print the table.*/ 2 | 3 | import java.util.Scanner; 4 | public class Solution { 5 | 6 | 7 | public static void main(String[] args) { 8 | 9 | /* Your class should be named Solution. 10 | * Read input as specified in the question. 11 | * Print output as specified in the question. 12 | */ 13 | Scanner scan = new Scanner(System.in); 14 | int s = scan.nextInt(); 15 | int e = scan.nextInt(); 16 | int w = scan.nextInt(); 17 | for(int i = s;i <= e;i = i+w){ 18 | int celsius = ((i-32)*5)/9; 19 | System.out.println(i + "\t" + celsius); 20 | } 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/18. Primality Check.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/18. Primality Check.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/19. Find the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/19. Find the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/2. Find the output.txt: -------------------------------------------------------------------------------- 1 | public class Solution{ 2 | public static void main(String [] args) { 3 | double a = 6 / 4; 4 | int b = 6 / 4; 5 | double c = a + b; 6 | System.out.println(c); 7 | } 8 | } 9 | 10 | Options 11 | 3.0 12 | 1.5 13 | 2.0 ✔ 14 | 2.5 -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/20. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/20. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/21. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/21. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/22. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/22. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/23. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/23. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/24. What is the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/24. What is the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/3. Predict the output.txt: -------------------------------------------------------------------------------- 1 | public class Solution{ 2 | public static void main(String [] args) { 3 | double a = 55.5; 4 | int b = 55; 5 | a = a % 10; 6 | b = b % 10; 7 | System.out.println(a + " " + b); 8 | } 9 | } 10 | 11 | Options 12 | 5 5 13 | 5.5 5 ✔ 14 | 6 5 15 | None of these -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/4.Find output.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/4.Find output.txt -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/5. Find Output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/5. Find Output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/6. Find the Output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/6. Find the Output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/7. Figure out the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/7. Figure out the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/8. What will be the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/8. What will be the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/9. Positive Negative.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 4 Conditionals and Loops/9. Positive Negative.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/Assignment- Conditionals and Loops/Factors.java: -------------------------------------------------------------------------------- 1 | // Write a program to print all the factors of a number other than 1 and the number itself. 2 | 3 | import java.util.Scanner; 4 | 5 | public class Factors { 6 | 7 | public static void main(String[] args) { 8 | // Write your code here 9 | Scanner scan = new Scanner(System.in); 10 | int n = scan.nextInt(); 11 | for (int i = 2; i < n; i++) { 12 | if (n % i == 0) 13 | System.out.print(i + " "); 14 | } 15 | scan.close(); 16 | } 17 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/Assignment- Conditionals and Loops/FindPowerOfNumber.java: -------------------------------------------------------------------------------- 1 | // Write a program to find x to the power n (i.e. x^n). Take x and n from the user. You need to print the answer. 2 | // Note : For this question, you can assume that 0 raised to the power of 0 is 1 3 | 4 | import java.util.Scanner; 5 | 6 | public class FindPowerOfNumber { 7 | public static void main(String[] args) { 8 | // Write your code here 9 | Scanner scan = new Scanner(System.in); 10 | int x = scan.nextInt(); 11 | int n = scan.nextInt(); 12 | int result = 1; 13 | for (int i = 1; i <= n; i++) { 14 | result = result * x; 15 | } 16 | System.out.println(result); 17 | scan.close(); 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/Assignment- Conditionals and Loops/MultiplicationTable.java: -------------------------------------------------------------------------------- 1 | // Write a program to print multiplication table of n 2 | 3 | import java.util.Scanner; 4 | 5 | public class MultiplicationTable { 6 | 7 | public static void main(String[] args) { 8 | // Write your code here 9 | Scanner scan = new Scanner(System.in); 10 | int n = scan.nextInt(); 11 | for (int i = 1; i <= 10; i++) { 12 | System.out.println(n * i); 13 | } 14 | scan.close(); 15 | } 16 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/Assignment- Conditionals and Loops/SumEvenOdd.java: -------------------------------------------------------------------------------- 1 | // Write a program to input an integer N and print the sum of all its even digits and sum of all its odd digits separately.Digits mean numbers,not the places!That is,if the given integer is"13245",even digits are 2&4 and odd digits are 1,3&5. 2 | 3 | import java.util.Scanner; 4 | 5 | public class SumEvenOdd { 6 | 7 | public static void main(String[] args) { 8 | // Write your code here 9 | Scanner scan = new Scanner(System.in); 10 | int n = scan.nextInt(); 11 | int evenSum = 0; 12 | int oddSum = 0; 13 | 14 | while (n != 0) { 15 | int i = n % 10; 16 | n = n / 10; 17 | if (i % 2 == 0) 18 | evenSum += i; 19 | else 20 | oddSum += i; 21 | } 22 | 23 | System.out.println(evenSum + " " + oddSum); 24 | scan.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 4 Conditionals and Loops/Assignment- Conditionals and Loops/totalSalary.java: -------------------------------------------------------------------------------- 1 | /*Write a program to calculate the total salary of a person. The user has to enter the basic salary (an integer) and the grade (an uppercase character), and depending upon which the total salary is calculated as - 2 | totalSalary = basic + hra + da + allow – pf */ 3 | 4 | import java.util.Scanner; 5 | 6 | public class totalSalary { 7 | public static void main(String[] args) { 8 | Scanner sc = new Scanner(System.in); 9 | long bs = sc.nextLong(); 10 | char grade = sc.next().charAt(0); 11 | double hra = 0.0; 12 | double da = 0.0; 13 | double allow = 0.0; 14 | double pf = 0.0; 15 | long total = 0l; 16 | if (bs >= 0 && bs <= 7500000) { 17 | hra = 0.20 * bs; 18 | da = 0.50 * bs; 19 | switch (grade) { 20 | case 'A': 21 | case 'a': 22 | allow = 1700.0; 23 | break; 24 | case 'B': 25 | case 'b': 26 | allow = 1500.0; 27 | break; 28 | } 29 | pf = 0.11 * bs; 30 | } 31 | total = (long) Math.round(bs + hra + da + allow - pf); 32 | System.out.println(total); 33 | sc.close(); 34 | } 35 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/AlphaPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class AlphaPattern { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Your class should be named Solution. Read input as specified in the question. 9 | * Print output as specified in the question. 10 | */ 11 | Scanner scan = new Scanner(System.in); 12 | int n = scan.nextInt(); 13 | char c = 'A'; 14 | for (int i = 1; i <= n; i++) { 15 | for (int j = 0; j < i; j++) { 16 | System.out.print(c); 17 | } 18 | System.out.println(); 19 | c++; 20 | } 21 | scan.close(); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/CharacterPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class CharacterPattern { 4 | 5 | public static void main(String[] args) { 6 | 7 | /* 8 | * Your class should be named Solution. Read input as specified in the question. 9 | * Print output as specified in the question. 10 | */ 11 | Scanner scan = new Scanner(System.in); 12 | int n = scan.nextInt(); 13 | char c = 'A'; 14 | for (int i = 1; i <= n; i++) { 15 | char ch = c; 16 | for (int j = 0; j < i; j++) { 17 | System.out.print(ch++); 18 | } 19 | System.out.println(); 20 | c++; 21 | } 22 | scan.close(); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/InterestingAlphabets.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class InterestingAlphabets { 4 | public static void main(String[] args) { 5 | // Your code goes here 6 | Scanner scan = new Scanner(System.in); 7 | int n = scan.nextInt(); 8 | char ch = 'A'; 9 | 10 | for (int i = 0; i < n - 1; i++) 11 | ch++; 12 | 13 | for (int i = 1; i <= n; i++) { 14 | char c = ch; 15 | for (int j = 0; j < i; j++) { 16 | System.out.print(c++); 17 | } 18 | System.out.println(); 19 | ch--; 20 | } 21 | scan.close(); 22 | } 23 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/ReverseNumberPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class ReverseNumberPattern { 4 | public static void main(String[] args) { 5 | 6 | /* 7 | * Your class should be named Solution. Read input as specified in the question. 8 | * Print output as specified in the question. 9 | */ 10 | 11 | Scanner scan = new Scanner(System.in); 12 | int n = scan.nextInt(); 13 | for (int i = 1; i <= n; i++) { 14 | for (int j = i; j >= 1; j--) { 15 | System.out.print(j); 16 | } 17 | System.out.println(); 18 | } 19 | scan.close(); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/SquarePattern.java: -------------------------------------------------------------------------------- 1 | /* Pattern for N = 4 2 | 4444 3 | 4444 4 | 4444 5 | 4444 */ 6 | 7 | import java.util.*; 8 | 9 | public class SquarePattern { 10 | public static void main(String[] args) { 11 | 12 | /* 13 | * Your class should be named Solution. Read input as specified in the question. 14 | * Print output as specified in the question. 15 | */ 16 | Scanner scan = new Scanner(System.in); 17 | int n = scan.nextInt(); 18 | for (int i = 0; i < n; i++) { 19 | for (int j = 0; j < n; j++) { 20 | System.out.print(n); 21 | } 22 | System.out.println(); 23 | } 24 | scan.close(); 25 | 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/TriangularNumberPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class TriangularNumberPattern { 4 | public static void main(String[] args) { 5 | 6 | /* 7 | * Your class should be named Solution. Read input as specified in the question. 8 | * Print output as specified in the question. 9 | */ 10 | Scanner scan = new Scanner(System.in); 11 | int n = scan.nextInt(); 12 | for (int i = 1; i <= n; i++) { 13 | for (int j = 0; j < i; j++) { 14 | System.out.print(i); 15 | } 16 | System.out.println(); 17 | } 18 | scan.close(); 19 | 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/TriangularStarPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class TriangularStarPattern { 4 | public static void main(String[] args) { 5 | 6 | /* 7 | * Your class should be named Solution. Read input as specified in the question. 8 | * Print output as specified in the question. 9 | */ 10 | Scanner scan = new Scanner(System.in); 11 | int n = scan.nextInt(); 12 | for (int i = 1; i <= n; i++) { 13 | for (int j = 0; j < i; j++) { 14 | System.out.print("*"); 15 | } 16 | System.out.println(); 17 | } 18 | scan.close(); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 5 Patterns - 1/test.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class test { 4 | public static void main(String[] args) { 5 | int[] input = { 3, 1, 4 }; 6 | int sum5 = 0; 7 | int sum3 = 0; 8 | int rest[] = new int[input.length]; 9 | int j = 0; 10 | for (int i = 0; i < input.length; i++) { 11 | if (input[i] % 5 == 0) 12 | sum5 += input[i]; 13 | else if (input[i] % 3 == 0) 14 | sum3 += input[i]; 15 | else { 16 | rest[j] = input[i]; 17 | j++; 18 | } 19 | } 20 | Arrays.sort(rest); 21 | System.out.println(Arrays.toString(rest)); 22 | System.out.println(sum3 + " " + sum5); 23 | j = rest.length - 1; 24 | while (j >= 0) { 25 | if (sum3 < sum5) { 26 | sum3 += rest[j]; 27 | j--; 28 | } else { 29 | sum5 += rest[j]; 30 | j--; 31 | } 32 | } 33 | System.out.println(sum3 + " " + sum5); 34 | System.out.println(sum3 == sum5); 35 | } 36 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 6 Patterns - 2/Assignment/Half Diamond Pattern.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Solution { 3 | 4 | public static void main(String[] args) { 5 | // Write your code here 6 | Scanner scan = new Scanner(System.in); 7 | int n = scan.nextInt(); 8 | int i = 1; 9 | while(i <= n+1){ 10 | int j = 1; 11 | while(j <= i-1){ 12 | System.out.print(j); 13 | j++; 14 | } 15 | int k = j-2; 16 | while(k >= 1){ 17 | System.out.print(k--); 18 | } 19 | i++; 20 | System.out.println("*"); 21 | System.out.print("*"); 22 | } 23 | i = 1; 24 | while(i <= n){ 25 | int j = 1; 26 | while(j <= n-i){ 27 | System.out.print(j++); 28 | } 29 | int k = j-2; 30 | j = 1; 31 | while(j <= n-1-i){ 32 | System.out.print(k--); 33 | j++; 34 | } 35 | i++; 36 | System.out.println("*"); 37 | System.out.print("*"); 38 | if(i == n) 39 | break; 40 | } 41 | 42 | } 43 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 6 Patterns - 2/Assignment/Odd Square.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Write your code here 6 | Scanner scan = new Scanner(System.in); 7 | int n = scan.nextInt(); 8 | int max = 1; 9 | for(int i=0; i max) 18 | count = 1; 19 | System.out.print(count); 20 | count = count + 2; 21 | } 22 | System.out.println(); 23 | c = c+2; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 6 Patterns - 2/Assignment/Parallelogram Pattern.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Write your code here 6 | Scanner scan = new Scanner(System.in); 7 | int n = scan.nextInt(); 8 | int i = 1; 9 | while(i <= n){ 10 | int spaces = 1; 11 | while(spaces <= i-1){ 12 | System.out.print(" "); 13 | spaces++; 14 | } 15 | int j = 1; 16 | while(j <= n){ 17 | System.out.print("*"); 18 | j++; 19 | } 20 | i++; 21 | System.out.println(); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 6 Patterns - 2/Assignment/Sum Pattern.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Main { 3 | 4 | public static void main(String[] args) { 5 | // Write your code here 6 | Scanner scan = new Scanner(System.in); 7 | int n = scan.nextInt(); 8 | 9 | int i =1; 10 | int sum = 0; 11 | while(i <= n){ 12 | int j = 1; 13 | while(j <= i){ 14 | System.out.print(j); 15 | sum = sum + j; 16 | j++; 17 | if(j > i) 18 | break; 19 | System.out.print("+"); 20 | } 21 | i++; 22 | System.out.println("=" + sum); 23 | sum = 0; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 6 Patterns - 2/Diamond of stars.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Solution { 3 | 4 | public static void main(String[] args) { 5 | // Write your code here 6 | Scanner scan = new Scanner(System.in); 7 | int n = scan.nextInt(); 8 | n = n/2 +1; 9 | int i = 1; 10 | while(i <= n){ 11 | int spaces = 1; 12 | while(spaces <= n-i){ 13 | System.out.print(" "); 14 | spaces++; 15 | } 16 | int j = 1; 17 | while(j <= i){ 18 | System.out.print("*"); 19 | j++; 20 | } 21 | int k = 1; 22 | while(k <= i-1){ 23 | System.out.print("*"); 24 | k++; 25 | } 26 | i++; 27 | System.out.println(); 28 | } 29 | i = 1; 30 | while(i <= n-1){ 31 | int spaces = 1; 32 | while(spaces <= i){ 33 | System.out.print(" "); 34 | spaces++; 35 | } 36 | int j = 1; 37 | while(j <= n-i){ 38 | System.out.print("*"); 39 | j++; 40 | } 41 | int k = 1; 42 | while(k <= j-2){ 43 | System.out.print("*"); 44 | k++; 45 | } 46 | 47 | i++; 48 | System.out.println(); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 6 Patterns - 2/Inverted Number Pattern.txt: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Solution { 3 | 4 | 5 | public static void main(String[] args) { 6 | 7 | /* Your class should be named Solution. 8 | * Read input as specified in the question. 9 | * Print output as specified in the question. 10 | */ 11 | Scanner scan = new Scanner(System.in); 12 | int n = scan.nextInt(); 13 | 14 | for(int i=n; i>=1; i--) 15 | { 16 | for(int j=0; j 0) { 30 | int r = n % 10; 31 | n = n / 10; 32 | reverse = reverse * 10 + r; 33 | } 34 | System.out.println(reverse); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 7 Operators and For loops/Assignment/Square Root (Integral).txt: -------------------------------------------------------------------------------- 1 | Given a number N, find its square root. You need to find and print only the integral part of square root of N. 2 | For eg. if number given is 18, answer is 4. 3 | Input format : 4 | Integer N 5 | Output Format : 6 | Square root of N (integer part only) 7 | Constraints : 8 | 0 <= N <= 10^8 9 | Sample Input 1 : 10 | 10 11 | Sample Output 1 : 12 | 3 13 | Sample Input 2 : 14 | 4 15 | Sample Output 2 : 16 | 2 17 | 18 | 19 | import java.util.Scanner; 20 | public class Main { 21 | 22 | public static void main(String[] args) { 23 | // Write your code here 24 | Scanner scan = new Scanner(System.in); 25 | int n = scan.nextInt(); 26 | if(n == 0 || n == 1){ 27 | System.out.println(n); 28 | System.exit(0); 29 | } 30 | int i = 1; 31 | int r = 1; 32 | while(r <= n){ 33 | i++; 34 | r = i*i; 35 | } 36 | System.out.println(i-1); 37 | 38 | } 39 | } -------------------------------------------------------------------------------- /Introduction to Java/Lecture 7 Operators and For loops/Assignment/Sum or Product.txt: -------------------------------------------------------------------------------- 1 | Write a program that asks the user for a number N and a choice C. And then give them the possibility to choose between computing the sum and computing the product of all integers in the range 1 to N (both inclusive). 2 | If C is equal to - 3 | 1, then print the sum 4 | 2, then print the product 5 | Any other number, then print '-1' (without the quotes) 6 | Input format : 7 | Line 1 : Integer N 8 | Line 2 : Choice C 9 | Output Format : 10 | Sum or product according to user's choice 11 | Constraints : 12 | 1 <= N <= 12 13 | Sample Input 1 : 14 | 10 15 | 1 16 | Sample Output 1 : 17 | 55 18 | Sample Input 2 : 19 | 10 20 | 2 21 | Sample Output 2 : 22 | 3628800 23 | Sample Input 3 : 24 | 10 25 | 4 26 | Sample Output 3 : 27 | -1 28 | 29 | 30 | import java.util.Scanner; 31 | public class Main { 32 | 33 | public static void main(String[] args) { 34 | // Write your code here 35 | Scanner scan = new Scanner(System.in); 36 | int n = scan.nextInt(); 37 | int c= scan.nextInt(); 38 | int sum = 0; 39 | int product =1; 40 | for(int i=1; i<=n; i++){ 41 | sum += i; 42 | product *= i; 43 | } 44 | if(c==1) 45 | System.out.println(sum); 46 | else if(c==2) 47 | System.out.println(product); 48 | else 49 | System.out.println(-1); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 7 Operators and For loops/Assignment/Terms of AP.txt: -------------------------------------------------------------------------------- 1 | Write a program to print first x terms of the series 3N + 2 which are not multiples of 4. 2 | Input format : 3 | Integer x 4 | Output format : 5 | Terms of series (separated by space) 6 | Constraints : 7 | 1 <= N <= 1,000 8 | Sample Input 1 : 9 | 10 10 | Sample Output 1 : 11 | 5 11 14 17 23 26 29 35 38 41 12 | Sample Input 2 : 13 | 4 14 | Sample Output 2 : 15 | 5 11 14 17 16 | 17 | 18 | import java.util.Scanner; 19 | public class Main { 20 | 21 | public static void main(String[] args) { 22 | // Write your code here 23 | Scanner scan = new Scanner(System.in); 24 | int n = scan.nextInt(); 25 | int count = 1; 26 | int i = 1; 27 | while(count <= n){ 28 | int num = 3*i + 2; 29 | if(num%4 != 0){ 30 | System.out.print(num + " "); 31 | count++; 32 | } 33 | i++; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 7 Operators and For loops/Notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 7 Operators and For loops/Notes.pdf -------------------------------------------------------------------------------- /Introduction to Java/Lecture 8 Test 1/CheckArmstrong.java: -------------------------------------------------------------------------------- 1 | /* Write a Program to determine if the given number is Armstrong number or not. Print true if number is armstrong, otherwise print false. 2 | An Armstrong number is a number (with digits n) such that the sum of its digits raised to nth power is equal to the number itself. 3 | For example, 4 | 371, as 3^3 + 7^3 + 1^3 = 371 5 | 1634, as 1^4 + 6^4 + 3^4 + 4^4 = 1634 6 | Input Format : 7 | Integer n 8 | Output Format : 9 | true or false 10 | Sample Input 1 : 11 | 1 12 | Sample Output 1 : 13 | true 14 | Sample Input 2 : 15 | 103 16 | Sample Output 2 : 17 | false */ 18 | 19 | import java.util.Scanner; 20 | 21 | public class CheckArmstrong { 22 | 23 | public static void main(String[] args) { 24 | // Write your code here 25 | Scanner scan = new Scanner(System.in); 26 | int n = scan.nextInt(); 27 | 28 | int result = 0; 29 | int original = n; 30 | int num = n; 31 | int count = 0; 32 | while (num != 0) { 33 | num = num / 10; 34 | count++; 35 | } 36 | while (n != 0) { 37 | int r = n % 10; 38 | n = n / 10; 39 | result = (int) (result + Math.pow(r, count)); 40 | } 41 | if (result == original) { 42 | System.out.println(true); 43 | } else 44 | System.out.println(false); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 8 Test 1/NumberStarPattern1.java: -------------------------------------------------------------------------------- 1 | /* Print the following pattern for given number of rows. 2 | Input format : 3 | Integer N (Total number of rows) 4 | Output Format : 5 | Pattern in N lines 6 | Sample Input : 7 | 5 8 | Sample Output : 9 | 5432* 10 | 543*1 11 | 54*21 12 | 5*321 13 | *4321 */ 14 | 15 | import java.util.Scanner; 16 | 17 | public class NumberStarPattern1 { 18 | 19 | public static void main(String[] args) { 20 | // Write your code here 21 | Scanner scan = new Scanner(System.in); 22 | int n = scan.nextInt(); 23 | 24 | int i = 1; 25 | int c = n; 26 | while (i <= n) { 27 | int j = n; 28 | while (j >= 1) { 29 | if (j == i) { 30 | System.out.print("*"); 31 | j--; 32 | } else { 33 | System.out.print(j--); 34 | } 35 | } 36 | System.out.println(); 37 | i++; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/1. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/1. Predict the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/10. Check for error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/10. Check for error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/11. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/11. Predict the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/12. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/12. Fill the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/13. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/13. Fill the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/14. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/14. Fill the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/15. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/15. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/16. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/16. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/17. Check prime.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/17. Check prime.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/18. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/18. Predict the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/19. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/19. Predict the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/2. Return type.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/2. Return type.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/3. Return type.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/3. Return type.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/4. Fill the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/4. Fill the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/5. Find the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/5. Find the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/6. Return type.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/6. Return type.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/7. Check the error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/7. Check the error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/8. Check for error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/8. Check for error.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/9. Predict the output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/9. Predict the output.PNG -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/FibonacciTest.java: -------------------------------------------------------------------------------- 1 | /* Given a number N, figure out if it is a member of fibonacci series or not. Return true if the number is member of fibonacci series else false. 2 | Fibonacci Series is defined by the recurrence 3 | F(n) = F(n-1) + F(n-2) 4 | where F(0) = 0 and F(1) = 1 5 | 6 | 7 | Input Format : 8 | Integer N 9 | Output Format : 10 | true or false 11 | Constraints : 12 | 0 <= n <= 10^4 13 | Sample Input 1 : 14 | 5 15 | Sample Output 1 : 16 | true 17 | Sample Input 2 : 18 | 14 19 | Sample Output 2 : 20 | false */ 21 | 22 | import java.util.Scanner; 23 | 24 | public class FibonacciTest { 25 | 26 | public static boolean checkMember(int n) { 27 | return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4); 28 | } 29 | 30 | public static boolean isPerfectSquare(int x) { 31 | int s = (int) Math.sqrt(x); 32 | return (s * s == x); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Introduction to Java/Lecture 9 Functions & Scope/Functions notes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vp3008/Coding-Ninjas--MERN-Stack-with-Java/614ea96b549f239b5d50171e3e8394b5d4012465/Introduction to Java/Lecture 9 Functions & Scope/Functions notes.pdf -------------------------------------------------------------------------------- /Introduction to Java/Test 2/MinimumWordLength.java: -------------------------------------------------------------------------------- 1 | /* Given a string S (that can contain multiple words), you need to find the word which has minimum length. 2 | Note : If multiple words are of same length, then answer will be first minimum length word in the string. 3 | Words are seperated by single space only. 4 | Input Format : 5 | String S 6 | Output Format : 7 | Minimum length word 8 | Constraints : 9 | 1 <= Length of String S <= 10^5 10 | Sample Input 1 : 11 | this is test string 12 | Sample Output 1 : 13 | is 14 | Sample Input 2 : 15 | abc de ghihjk a uvw h j 16 | Sample Output 2 : 17 | a */ 18 | 19 | 20 | 21 | public class MinimumWordLength { 22 | 23 | public static String minLengthWord(String input){ 24 | 25 | // Write your code here 26 | String[] arr = input.split(" "); 27 | int min = Integer.MAX_VALUE; 28 | String minWord = ""; 29 | for(int i=0; i