Пікірлер
@DeveloperCoder
@DeveloperCoder 3 күн бұрын
import java.util.*; class Solution { public List<Integer> findMinHeightTrees(int n, int[][] edges) { if (n == 1) { return Collections.singletonList(0); } List<Integer> result = new ArrayList<>(); Map<Integer, List<Integer>> map = new HashMap<>(); // Build the adjacency list for (int[] edge : edges) { int u = edge[0]; int v = edge[1]; map.computeIfAbsent(u, k -> new ArrayList<>()).add(v); map.computeIfAbsent(v, k -> new ArrayList<>()).add(u); } Queue<Integer> leaves = new LinkedList<>(); // Add initial leaf nodes to the queue for (int node : map.keySet()) { if (map.get(node).size() == 1) { leaves.offer(node); } } while (n > 2) { int size = leaves.size(); n -= size; for (int i = 0; i < size; i++) { int leaf = leaves.poll(); int neighbor = map.get(leaf).iterator().next(); // Get the only neighbor map.get(neighbor).remove(Integer.valueOf(leaf)); // Remove leaf from neighbor's adjacency list if (map.get(neighbor).size() == 1) { leaves.offer(neighbor); } } } result.addAll(leaves); return result; } }
@debojeetdutta1390
@debojeetdutta1390 5 күн бұрын
give the code
@aslesh-lj6wc
@aslesh-lj6wc 8 күн бұрын
errors from EmployeeMapper = java: cannot find symbol symbol: method getLastName() location: variable employeeDto of type com.developer.coder.ems.dto.EmployeeDto also the same for employee too
@shouryapratapsinghchouhan1648
@shouryapratapsinghchouhan1648 26 күн бұрын
Q2
@DeveloperCoder
@DeveloperCoder 26 күн бұрын
Done...kzbin.info/www/bejne/Y4OneKuBhpqDrJI
@shashwatpandey6446
@shashwatpandey6446 27 күн бұрын
Bro, thumbnail??☠
@DeveloperCoder
@DeveloperCoder 27 күн бұрын
😜
@AnshulKotwal-r2o
@AnshulKotwal-r2o Ай бұрын
thank you
@piyushchauhan2898
@piyushchauhan2898 Ай бұрын
Lage raho bro ❤
@DeveloperCoder
@DeveloperCoder Ай бұрын
DP: class Solution { public long minimumTotalDistance(List<Integer> robot, int[][] factory) { Collections.sort(robot); Arrays.sort(factory, Comparator.comparingInt(a -> a[0])); List<Integer> factoryPositions = new ArrayList<>(); for (int[] f : factory) { for (int i = 0; i < f[1]; i++) { factoryPositions.add(f[0]); } } int robotCount = robot.size(); int factoryCount = factoryPositions.size(); long[] next = new long[factoryCount+1]; long[] current = new long[factoryCount+1]; for( int i=robotCount -1;i>=0;i--){ //no factories left case if(i!= robotCount -1 ) next[factoryCount] = (long) 1e12; current[factoryCount] = (long) 1e12; for(int j = factoryCount -1 ;j>=0;j--){ //assign current robot to current factory long assign = Math.abs((long) robot.get(i) - factoryPositions.get(j)) + next[j+1]; //skip current factory for this robot long skip = current[j+1]; //take the min option current[j] = Math.min(assign,skip); } System.arraycopy(current,0,next,0,factoryCount+1); } return current[0]; } }
@DeveloperCoder
@DeveloperCoder Ай бұрын
Recursion+Memo class Solution { public long minimumTotalDistance(List<Integer> robot, int[][] factory) { Collections.sort(robot); Arrays.sort(factory, Comparator.comparingInt(a -> a[0])); List<Integer> factoryPositions = new ArrayList<>(); for(int[] f : factory ){ for(int i=0;i<f[1];i++){ factoryPositions.add(f[0]); } } int robotCount = robot.size(); int factoryCount = factoryPositions.size(); long[][] memo = new long[robotCount][factoryCount]; for(long[] row: memo){ Arrays.fill(row, -1); } return calculateMinDistance(0,0, robot, factoryPositions, memo); } private long calculateMinDistance(int robotIdx, int factoryIdx, List<Integer> robot, List<Integer> factoryPositions, long[][] memo ){ //All robots assigned if(robotIdx == robot.size()) return 0; //No factories left to assign if(factoryIdx == factoryPositions.size()) return (long) 1e12; //check memo if(memo[robotIdx][factoryIdx] != -1){ return memo[robotIdx][factoryIdx]; } //option:1 assign current robot to current factory long assign = Math.abs(robot.get(robotIdx) - factoryPositions.get(factoryIdx)) + calculateMinDistance(robotIdx+1,factoryIdx+1, robot, factoryPositions, memo); //option:2 Skip current factory for the current robot long skip = calculateMinDistance(robotIdx,factoryIdx + 1, robot, factoryPositions, memo); memo[robotIdx][factoryIdx] = Math.min(assign,skip); return memo[robotIdx][factoryIdx]; } }
@arihantsinghrana2173
@arihantsinghrana2173 Ай бұрын
can you provide the code for both approaches
@DeveloperCoder
@DeveloperCoder Ай бұрын
Sure, I have added the code in comments.😊
@arihantsinghrana2173
@arihantsinghrana2173 Ай бұрын
@@DeveloperCoder Thank brother
@naruto_6663
@naruto_6663 2 ай бұрын
you should provide some soft copy of the code
@KISHANYadav-hv7wd
@KISHANYadav-hv7wd 2 ай бұрын
Thanks for hint here is my solution which got accepted! Java class Solution { public int lengthAfterTransformations(String s, int t) { int mod=1000000007; int[] hash=new int[26]; int ans=0; for(int i=0;i<s.length();i++){ char c=s.charAt(i); hash[c-'a']++; } for(int i=0;i<t;i++){ int a=hash[25],b=hash[25]; hash[25]=0; for(int j=25;j>0;j--){ hash[j]=hash[j-1]; hash[j-1]=0; } hash[0]=a; hash[1]=(hash[1]+b)%mod; } for(int ele:hash){ ans=(ans%mod+ele)%mod; } return ans; } }
@chaurasiyachaitanya6657
@chaurasiyachaitanya6657 2 ай бұрын
Nice explanation.. Keep it up bro👍
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
@@chaurasiyachaitanya6657 thanks 🙏☺️
@AbiramiKalaiSelvan
@AbiramiKalaiSelvan 2 ай бұрын
sir pls explain how the code will work on it by step by step explain with example
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
Please try 🎧 incase voice is not clear and audible. Getting some issues with the old recorder.😊
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
2 pointers: (Sliding Window) (Time Complexity) Let n be the total number of elements across all lists and k be the number of lists. Time complexity: O(nlogn) The first nested loop iterates over k lists, and for each list, it iterates through its elements. In the worst case, this requires O(n) time since we are processing all elements once. After merging, we sort the merged array which contains n elements. Sorting has a time complexity of O(nlogn). The two-pointer approach iterates through the merged list once (with the right pointer) and may also move the left pointer forward multiple times. In total, each pointer will traverse the merged list at most n times. Combining these steps, the overall time complexity is: O(nlogn)
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
Priority Queue: (Time Complexity) Let n be the total number of elements across all lists and k be the number of lists. Time complexity: O(nlogk) The initial loop that inserts the first element from each list into the priority queue runs in O(k). The while loop continues until we have exhausted one of the lists in the priority queue. Each iteration of the loop involves: Extracting the minimum element from the priority queue, which takes O(logk). Inserting a new element from the same list into the priority queue, which also takes O(logk). In the worst case, we will process all n elements, leading to a total complexity of O(nlogk).
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
Brute Force: (Time Complexity ) Let n be the total number of elements across all lists and k be the number of lists. Time complexity: O(n⋅k) In each iteration of the while (true) loop, we traverse all k lists to find the current minimum and maximum. This takes O(k) time. The loop continues until at least one of the lists is fully traversed. In the worst case, every element from every list is visited, and the total number of elements across all lists is n. Therefore, the loop runs O(n) times. Overall, the time complexity becomes O(n⋅k).
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
Using Arrays: class CustomStack { private int[] stack; // Array to store the stack elements private int top; // Pointer to the top of the stack private int maxSize; // Maximum size of the stack // Constructor to initialize the stack and set the maximum size public CustomStack(int maxSize) { this.stack = new int[maxSize]; // Fixed-size array for the stack this.top = -1; // Initialize top as -1 (empty stack) this.maxSize = maxSize; } // Pushes an element onto the stack if there's space public void push(int x) { if (top < maxSize - 1) { // Check if there's space in the stack top++; // Move top pointer to the next empty spot stack[top] = x; // Add element to the stack } } // Pops and returns the top element of the stack, or -1 if it's empty public int pop() { if (top == -1) { // If the stack is empty, return -1 return -1; } else { return stack[top--]; // Return top element and decrement the top pointer } } // Increments the bottom k elements by val public void increment(int k, int val) { int limit = Math.min(k, top + 1); // Find how many elements we can increment for (int i = 0; i < limit; i++) { stack[i] += val; // Increment each of the bottom k elements } } } /** * Your CustomStack object will be instantiated and called as such: * CustomStack obj = new CustomStack(maxSize); * obj.push(x); * int param_2 = obj.pop(); * obj.increment(k,val); */
@DeveloperCoder
@DeveloperCoder 2 ай бұрын
Some more ways to solve this problem: Using ArrayList : class CustomStack { private ArrayList<Integer> stack; private int maxSize; public CustomStack(int maxSize) { this.stack = new ArrayList<>(); this.maxSize = maxSize; } // Pushes an element to the top of the stack if it hasn't reached the max size public void push(int x) { if (stack.size() < maxSize) { stack.add(x); } } // Pops and returns the top element of the stack or -1 if the stack is empty public int pop() { if (stack.isEmpty()) { return -1; } else { return stack.remove(stack.size() - 1); // Removes the top element } } // Increments the bottom k elements by val public void increment(int k, int val) { int limit = Math.min(k, stack.size()); // Ensures we don't exceed the stack size for (int i = 0; i < limit; i++) { stack.set(i, stack.get(i) + val); // Increment each of the bottom k elements } } }
@vignesh4602
@vignesh4602 3 ай бұрын
sir can you give the code for string approach for the above problem
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
String approach is not efficient enough for larger input sizes. With below approach, you won't be able to submit the solution. Only 30/38 testcases are getting passed class Solution { public int[] sumPrefixScores(String[] words) { int n = words.length; int[] result = new int[n]; // Iterate through each word in the array for (int i = 0; i < n; i++) { String word = words[i]; int score = 0; // Iterate through all prefixes of the word for (int j = 1; j <= word.length(); j++) { String prefix = word.substring(0, j); // Count how many words start with the current prefix for (String w : words) { if (w.startsWith(prefix)) { score++; } } } // Store the total score for the current word result[i] = score; } return result; } } The Trie data structure is the optimal choice for efficiently solving the prefix score problem, especially for larger inputs. It allows for quick insertion and lookup of prefixes, resulting in a more scalable solution. Try to solve this and yesterday's problem with Trie; you will be able to understand better.
@vignesh4602
@vignesh4602 3 ай бұрын
thanks for the explanation sir
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
Always welcome :)
@jd3287
@jd3287 3 ай бұрын
clear English, written out dry run, best explanation on youtube for this question! including time/space at the end would make this video a bit better. thank you!
@Coc-dr7gl
@Coc-dr7gl 3 ай бұрын
Hello brother, your tutorials are really helpful. I would like to contact you, if possible share your contact info..
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
Thank you😊😊. Please feel free to contact me : Email: [email protected]
@abhibhosale6877
@abhibhosale6877 3 ай бұрын
Nice
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
Thanks
@abhibhosale6877
@abhibhosale6877 3 ай бұрын
Nice one
@harshugamer7776
@harshugamer7776 3 ай бұрын
Bro please, first explain the problem then explain the solution , because it'll give us the time to try it by ourselves.. cause most newbies like me can't understand the problem like this ..
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
Sure...I am doing the same for daily problems... will implement your suggestion in upcoming weekly contest solutions.
@ganeshjaggineni4097
@ganeshjaggineni4097 3 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@versatile17
@versatile17 3 ай бұрын
Thanks for daily problem videos
@samtechsolutions777
@samtechsolutions777 3 ай бұрын
Hey please share this project GitHub link
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
Note: Please use earphones 🎧 for better audio quality. I hope everyone is able to send the data and get the list of employees using frontend part. If you have any queries, please let me know in the comments!!!! Consistency is the 🗝️ key to success!!!
@abhibhosale6877
@abhibhosale6877 3 ай бұрын
nice one
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
@@abhibhosale6877 thanks 🙏
@DeveloperCoder
@DeveloperCoder 3 ай бұрын
Approach 2 (Without using Map): import java.util.*; class Solution { public double maxProbability(int n, int[][] edges, double[] succProb, int start_node, int end_node) { List<double[]>[] graph = new List[n]; for (int i = 0; i < n; i++) { graph[i] = new ArrayList<>(); } for (int i = 0; i < edges.length; i++) { int u = edges[i][0]; int v = edges[i][1]; double p = succProb[i]; graph[u].add(new double[]{v, p}); graph[v].add(new double[]{u, p}); } PriorityQueue<double[]> pq = new PriorityQueue<>((a, b) -> Double.compare(b[1], a[1])); pq.add(new double[]{start_node, 1.0}); double[] r = new double[n]; r[start_node] = 1.0; while (!pq.isEmpty()) { double[] curr = pq.poll(); int u = (int) curr[0]; double p = curr[1]; if (u == end_node) { return p; } for (double[] neighbor : graph[u]) { int v = (int) neighbor[0]; double prob = p * neighbor[1]; if (prob > r[v]) { r[v] = prob; pq.add(new double[]{v, prob}); } } } return 0.0; } }
@Saivarun11
@Saivarun11 4 ай бұрын
Thank you so much! I was struggling to understand Spring Boot even after reading the documentation and searching everywhere, but this video explained it perfectly. As someone new to Spring Boot, this really helped me a lot!
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
Thank you so much for your kind words! 🌟 I'm really glad the video helped you understand Spring Boot better. It can be challenging when you're just starting out, but you're doing great by taking the time to learn. Keep up the awesome work, and if you have any more questions or topics you'd like to see, feel free to ask! 🚀😊
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
Hi Everyone, I hope you’ve all completed the backend and frontend tasks to retrieve the list of employees. If you’re encountering any issues, please let me know in the comments. Note: For better audio quality, please use earphones. There was an issue with the recorder that I discovered only after the recording was finished.
@davidtrame8280
@davidtrame8280 4 ай бұрын
Your audio is very hard to hear
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
@@davidtrame8280 Yes, please use earphones. There was an issue with the recorder that I discovered only after it was finished.
@ganeshjaggineni4097
@ganeshjaggineni4097 4 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
@@ganeshjaggineni4097 Thanks ☺️
@PallabChatterjee-n7x
@PallabChatterjee-n7x 4 ай бұрын
Use some light IDEs and create some moderate type projects using React and Spring Boot
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
Thank you for the suggestion! For Spring Boot, I recommend Eclipse or IntelliJ IDEA due to their strong Java support. For React, I prefer Visual Studio Code for its lightweight and customizable environment. If you have any specific project or topics in mind, I'd love to hear them!
@PallabChatterjee-n7x
@PallabChatterjee-n7x 4 ай бұрын
@@DeveloperCoder I have suggested you to use a light background theme so that the code is visible and please create a project series like a movie ticket website or some hotel management using React as Front End and Spring Boot as Backend
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
@@PallabChatterjee-n7x Sure thing!! Once this Employee management System frontend is done, will do others.
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
Part 1 : kzbin.info/www/bejne/j6nVe2B-bLprd8k
@sukanshigarg6051
@sukanshigarg6051 4 ай бұрын
@rohitsingh1350
@rohitsingh1350 4 ай бұрын
Nicely explained..
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
@@rohitsingh1350 thanks ☺️
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
I didn't have much time today, so I put this video together quickly to help you maintain your daily streak. If you have any questions or need further clarification, please let me know, and I'll do my best to provide a detailed explanation. Thank you for your understanding and support.😊
@shhivanshh
@shhivanshh 4 ай бұрын
I did not understand the input. We are provided with a 2D integer array and the input is string. And we haven't mentioned strings anywhere in the program and we are not checking with the string value then how are we able to determine if adjacent or diagonal value is asked. Can anyone explain?
@DeveloperCoder
@DeveloperCoder 4 ай бұрын
We have to just define the methods, that's all. We don't need to call anything from our side...in background it is calling everything itself... 1. List of Operations This is a list of strings indicating the type of operations or queries to perform: "neighborSum" "adjacentSum" "adjacentSum" "diagonalSum" "diagonalSum" 2. List of Parameters This list provides the parameters required for each operation: The first element is a 3x3 matrix: [[[0, 1, 2], [3, 4, 5], [6, 7, 8]]] The remaining elements are parameters for each operation in the form of integers or indices: [1], [4], [4], [8] Explanation of the Operations with Parameters: "neighborSum" with parameters [[[0, 1, 2], [3, 4, 5], [6, 7, 8]]]: The operation "neighborSum" likely calculates the sum of neighboring elements around a specified cell in the matrix. "adjacentSum" with parameter [1]: The operation "adjacentSum" is applied to the cell located at index [1] (in a flat representation of the matrix or a specific cell). "adjacentSum" with parameter [4]: Similarly, this operation "adjacentSum" is applied to the cell located at index [4]. "diagonalSum" with parameter [4]: The "diagonalSum" operation calculates the sum of elements along the diagonals passing through the cell at index [4]. "diagonalSum" with parameter [8]: This operation "diagonalSum" calculates the sum of elements along the diagonals passing through the cell at index [8].
@shhivanshh
@shhivanshh 4 ай бұрын
@@DeveloperCoder Thanks a lot for explaining in detail. I really appreciate your efforts
@absolvegaming570m4
@absolvegaming570m4 4 ай бұрын
Please
@absolvegaming570m4
@absolvegaming570m4 4 ай бұрын
Bro 2nd question ka solution
@xylox_editor
@xylox_editor 4 ай бұрын
How can they term it as "EASY"?
@juturtaur298
@juturtaur298 5 ай бұрын
Very simple and nice explanation , Thankyou, keep it up .
@DeveloperCoder
@DeveloperCoder 5 ай бұрын
Thank you!😀
@DeveloperCoder
@DeveloperCoder 5 ай бұрын
Correction: Instead of saying 1, 2, 4, 8 are divisible by 16, I mistakenly referred to 1, 2, 4, and 8 as special numbers. Ignore that part (from 03:24 to 03:42). Special numbers are only those that are divisible by 1 and are squares of prime numbers(2,3,5,7,11 etc), like 4, 9, 25, 49, and 121 are special numbers according to this problem.
@singh_1057
@singh_1057 5 ай бұрын
How 8 is a special number?
@DeveloperCoder
@DeveloperCoder 5 ай бұрын
Right, my bad. Instead of saying 1,2,4,8 are divisible of 16, I mentioned 1,2,4 and 8 as special number... Ignore that part (from 03:24 to 3:42)..special numbers are only those which are divisible by 1 and are square of prime numbers...like 4,9,25,49,121
@singh_1057
@singh_1057 5 ай бұрын
@@DeveloperCoder great explanation 👍
@DeveloperCoder
@DeveloperCoder 5 ай бұрын
@@singh_1057 Thank you 😃
@premkumar.b5410
@premkumar.b5410 5 ай бұрын
Great explanation
@DeveloperCoder
@DeveloperCoder 5 ай бұрын
Thank you 😊