Tumgik
codewithsanika · 1 year
Video
youtube
684. Redundant Connection
684. Redundant Connection In this tutorial, I walk you through step-by-step on how to approach Redundant Connection🧠💡 Don't miss out on learning this essential algorithmic problem. Watch the video now and level up your programming skills! 💪💻 #Programming #Algorithm #LeetCode #Tutorial #ProblemSolving #JAVA #RedundantConnection #UnionFind Approach There are two conditions here 1) Create Union Find Class which consist of Parent and Rank as arrays 2)Initialize Parent array and Rank array with the Constructor 3)Create a function Find (here we create function called "Find" to find the parent of the node) 4)Create a function Union(here we create function called "Union" to union the two nodes and then increase the weight accordingly. If Union is not possible then there is a "Cycle" between two nodes) 5)Now use this class in main function of Redundant Connection to find the node which has redundant connection #Summary: Union-Find Data Structure is used to find the connection between two nodes. Thus helps to determine whether two nodes are in the same connected component or not in the graph. It also helps in merging two nodes in the graph #TimeComplexity : O(n)
0 notes
codewithsanika · 1 year
Video
youtube
Pascal Triangle
In this tutorial, I walk you through step-by-step on how to approach Pascal Triangle🧠💡 Don't miss out on learning this essential algorithmic problem. Watch the video now and level up your programming skills! 💪💻 #Programming #Algorithm #PascalTriangle #LeetCode #Tutorial #ProblemSolving #JAVA #DynamicProgramming # Approach There are two conditions here 1) Condition - At the beginning and ending of each row we have 1 2)Recurrence Relation - which helps to use Dynamic Programming over here Steps: 1) Initialize List of List of Integer as Triangle 2) Triangle.add(new ArrayList) 3)Now add 1 to the first triangle(0)index 4)Now create new ArrayList for currRows and prevRows respectively 5)Add 1 to the beginning of currRows 6)For middle Numbers use recurrence relation (prevRows.get(col-1)+prevRows.get(col)) 7)Add 1 at the end of currRows 8)Return the triangle #Summary: Dynamic Programming is the technique use to breakdown the problems into subproblems and store the solution of subproblems. At the end use the subproblem solution to find out final solution #TimeComplexity : O(numRows2)
0 notes
codewithsanika · 1 year
Video
youtube
706. Design HashMap
https://www.youtube.com/watch?v=sgDIoUX0CFM
https://leetcode.com/problems/design-... In this tutorial, I walk you through step-by-step on how to approach Design HashMap🧠💡 Don't miss out on learning this essential algorithmic problem. Watch the video now and level up your programming skills! 💪💻 #Programming #Algorithm #DesignHashMap #LeetCode #Tutorial #ProblemSolving #JAVA Approach and Steps: 1) Initialize Entry class having key and value pair 2)Initialize  HashMap class with Array LinkedList containing Entry class. [Here we are creating Array of size 769 prime number which consist of buckets mapped to LinkedList of Entry class containing key and value pair] 3) Constructor class to initialize data structure of HashMap 4) Implement Put method (Find the bucket with the following formula key modulo size. if bucket itself is null then put key and value pair. But if key is present then just update with value) 5)Implement Get method (Find the bucket with the following formula key modulo size. If entries which are mapped to bucket are empty then return -1, but if we get the key then return its value) 6) Implement Remove method (Find the bucket with the following formula key modulo size. if bucket itself is null then continue. But if key is present then just remove that Entry of key and value pair from the bucket) #Summary: HashMap stores elements in key/value pairs. Here, keys are unique identifiers used to associate each value on a map. The HashMap class implements the Map interface. #TimeComplexity : O(1) Please Follow for more LeetCode problems
1 note · View note