🚀 Day 55 of my #100DaysOfCode Journey Today, I solved LeetCode problem Richest Customer Wealth Problem Insight: We are given a 2D array where each row represents a customer and each column represents their wealth in different banks. We need to find the maximum total wealth among all customers. Approach: • Traverse each row of the 2D array (each customer) • Calculate the sum of all bank accounts for that customer • Keep updating the maximum wealth found so far • Compare each row sum with the current maximum Code Idea Used: Nested loop traversal (matrix row-wise summation) Time Complexity: O(m × n) | Space Complexity:** O(1) Key Takeaway: Simple nested loops are powerful for matrix problems—focus on row-wise or column-wise aggregation depending on the requirement. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #100DaysOfCode #Arrays #MatrixProblems
Solving LeetCode Richest Customer Wealth Problem in Java
More Relevant Posts
-
🚀 Day 569 of #750DaysOfCode 🚀 🔍 Problem Solved: Minimize Hamming Distance After Swap Operations Today’s problem was a great reminder that not every swapping problem is about brute force — sometimes it’s about understanding connections. 💡 Key Insight: The given swaps form connected components (groups of indices). Within each component, we can rearrange elements freely. So instead of thinking about swaps individually, we: 👉 Treat each component as a bucket of values 👉 Try to match target values using available values in that bucket 🧠 Approach: Use Union-Find (DSU) to group indices Store frequency of values from source for each component Traverse target: If value exists in the same component → match it Else → count as mismatch ⚡ Complexity: Time: ~O(n) (thanks to path compression in DSU) Space: O(n) ✨ Takeaway: When swaps are allowed → think connected components When matching values → think frequency maps This combination shows up in many advanced problems — mastering it is a big win 💪 #LeetCode #DSA #Java #UnionFind #CodingJourney #ProblemSolving #Tech #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Multi-Source BFS with Conflict Resolution, but A Subtle Twist Solved an interesting problem during LeetCode Weekly Contest 498 (Q3) that looks like a standard BFS at first… but has a catch 👇 You’re given multiple source cells, each with a color. At every time step, colors spread to adjacent cells. But here’s the twist: 👉 If multiple colors reach the same cell at the same time, the cell takes the maximum color. 🧠 Key Insight A normal BFS doesn’t work directly because it processes nodes one by one. That can lead to assigning a smaller color before a larger one arrives in the same time step. The fix? ✅ Process BFS level by level (time steps) ✅ Collect updates for the entire level first ✅ Resolve conflicts using max color ✅ Apply updates after the level finishes 💡 Approach Use multi-source BFS (push all sources initially) For each level: Use a HashMap to track best color per cell Only update the grid after processing the full level ⚡ Complexity Time: O(n × m) Space: O(n × m) 🔥 Takeaway Whenever a problem involves: Simultaneous updates Tie-breaking rules at the same time step 👉 Think in terms of level-order BFS + delayed updates It’s always the “small twist” problems that force you to rethink standard patterns. How would you optimize this further (maybe avoid string keys in HashMap)? 👀 #LeetCode #WeeklyContest #Algorithms #BFS #Java #CodingInterview #ProblemSolving
To view or add a comment, sign in
-
-
Today I solved LeetCode 111 – Minimum Depth of Binary Tree. 🧩 Problem Summary: Given the root of a binary tree, return its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 💡 Key Concepts Used: Binary Trees Breadth First Search (BFS) Queue data structure Tree traversal 🧠 Approach: Use BFS (level order traversal) with a queue. Start from the root and process nodes level by level. The first time you encounter a leaf node, return the current depth. Since BFS explores level by level, it guarantees the shortest path. Alternative: Use recursion, but carefully handle cases where one subtree is null. ⏱ Time Complexity: O(N) — In the worst case, all nodes are visited. 📚 What I Learned: Why BFS is preferred for shortest path problems in trees. Difference between minimum depth vs maximum depth. Handling edge cases in tree recursion. Strengthening queue-based traversal concepts. Understanding when to use BFS vs DFS is key Consistency builds strong problem-solving skills #LeetCode #DSA #BinaryTree #MinimumDepth #BFS #Queue #Java #CodingJourney #ProblemSolving #100DaysOfCode #TechGrowth
To view or add a comment, sign in
-
-
Day 78/100 | #100DaysOfDSA 🧩🚀 Today’s problem: Maximum Level Sum of a Binary Tree A classic BFS (level-order traversal) problem on trees. Problem idea: Find the level of the tree that has the maximum sum of node values. Key idea: Level-order traversal using a queue. Why? • We need to process nodes level by level • BFS naturally groups nodes by levels • Easy to compute sum for each level How it works: • Use a queue to perform BFS • For each level: → Process all nodes in current queue size → Calculate the sum of that level • Track the maximum sum and corresponding level • Return the smallest level with maximum sum Time Complexity: O(n) Space Complexity: O(n) Big takeaway: Whenever a problem involves level-wise processing in trees, BFS is the go-to approach. 🔥 Day 78 done. 🚀 #100DaysOfCode #LeetCode #DSA #Algorithms #BinaryTree #BFS #LevelOrder #Java #CodingJourney #ProblemSolving #InterviewPrep #TechCommunity
To view or add a comment, sign in
-
-
🚀Day 40 LeetCode 1161 – Maximum Level Sum of a Binary Tree Ever wondered how to find the level of a binary tree with the maximum sum of node values? 🤔 Here’s the idea: We traverse the tree level by level (BFS) and compute the sum at each level. The trick is to keep track of the maximum sum and return the smallest level where this occurs. 💡 Key Insight: Level-order traversal (using a queue) naturally processes nodes one level at a time, making it perfect for this problem. 🔧 Approach: ✔ Use a queue for BFS ✔ For each level: • Calculate sum of nodes ✔ Track maximum sum and corresponding level 🔥 Takeaway: Whenever a problem involves levels in a tree, think BFS first — it often leads to the cleanest solution. #LeetCode #DataStructures #Java #CodingInterview #BinaryTree #BFS #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Solved LeetCode Problem #24 – Swap Nodes in Pairs Today I worked on a classic Linked List problem that focuses on pointer manipulation and in-place operations. 🔍 Problem Insight: Given a linked list, the task is to swap every two adjacent nodes and return the modified list — without changing node values, only by updating links. 💡 Approach Used: I used an iterative approach with a dummy node to simplify edge cases. By carefully updating pointers, I was able to swap nodes in pairs efficiently while traversing the list. 🧠 Key Learning: Importance of pointer manipulation in linked lists How a dummy node can simplify complex edge cases Writing clean and efficient in-place algorithms 📈 Complexity: Time: O(n) (single traversal) Space: O(1) (no extra memory used) ✨ Problems like this are great for strengthening: Linked List concepts In-place transformations Logical thinking and debugging skills Looking forward to solving more such problems and improving consistency! 💪 #LeetCode #DSA #LinkedList #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟖𝟏 – 𝐃𝐒𝐀 𝐉𝐨𝐮𝐫𝐧𝐞𝐲 | 𝐀𝐫𝐫𝐚𝐲𝐬 🚀 Today’s problem focused on finding two unique numbers where all others appear twice. 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐨𝐥𝐯𝐞𝐝 • Single Number III 🔗 https://lnkd.in/dEQaaF3F 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡 – 𝐁𝐢𝐭 𝐌𝐚𝐧𝐢𝐩𝐮𝐥𝐚𝐭𝐢𝐨𝐧 (𝐎𝐩𝐭𝐢𝐦𝐚𝐥) Steps: • XOR all elements → gives a ⊕ b (two unique numbers) • Find rightmost set bit → differentiates a & b • Divide numbers into 2 groups based on that bit • XOR each group → get the two unique numbers 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 • XOR cancels duplicate elements • Bit tricks help split data into meaningful groups • Problems can often be optimized from O(n²) → O(n) • Understanding bit-level operations is very powerful 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 • Time: O(n) • Space: O(1) 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲 When duplicates cancel out, think in terms of XOR and bit patterns. 81 days consistent 🚀 On to Day 82. #DSA #Arrays #BitManipulation #LeetCode #Java #ProblemSolving #DailyCoding #LearningInPublic #SoftwareDeveloper
To view or add a comment, sign in
-
-
Day 105 - LeetCode Journey Solved LeetCode 933: Number of Recent Calls ✅ Simple problem, but a great use of queue + sliding window concept. Idea: Store timestamps in a queue Remove all calls older than t - 3000 Remaining size = answer Key learnings: • Sliding window using queue • Maintaining only relevant data • Efficient real-time processing • Clean O(n) approach ✅ All test cases passed ⚡ O(1) amortized per operation Sometimes clean logic is all you need 💡 #LeetCode #DSA #Queue #SlidingWindow #Java #CodingJourney #ProblemSolving #InterviewPrep
To view or add a comment, sign in
-
-
So what kind of savings on tokens can you get from unstructured data? Well if you’re talking systems level code, it seems like 9x token savings is the answer. Other benchmarks I’ve run seems to be in agreement with this result. Still other engineers have reported similar results on benchmarks for Java codebases. I think it’s safe to conclude KestrelDB is doing great as the Agent Memory Infrastructure component. Next step get a bunch of people running it. Anyone keen on some consistent memory for their autonomous systems? 😊
To view or add a comment, sign in
-
-
🧠 LeetCode POTD — Why Union Find Works Here 1722. Minimize Hamming Distance After Swap Operations At first glance, this problem feels like a swapping problem. We are given: 👉 source[] 👉 target[] 👉 allowed index swaps And we need to minimize the Hamming distance. My first instinct was to think: Which swaps should I perform? What sequence gives the best result? But that quickly becomes messy. Too many possible swaps. Too many combinations. ⸻ 💡 Then the real insight appears: This problem is not about individual swaps. It’s about connectivity. If index 0 can swap with 1, and 1 can swap with 2 Then effectively: 👉 0, 1, 2 are all connected 👉 Any value inside this group can be rearranged freely That completely changes the problem. ⸻ 📌 This is where Union Find (DSU) fits perfectly. Use Union Find to group all indices that belong to the same connected component. Each component behaves like a bucket where values can be reordered in any way. ⸻ Why it works: Inside one connected component: 👉 Count frequencies of values from source 👉 Compare with values needed in target If target needs a value that exists in the same component: ✅ We can rearrange and match it If not: ❌ That position contributes to Hamming distance ⸻ Example: source = [1,2,3,4] target = [2,1,4,5] allowed swaps connect {0,1} and {2,3} So: Group 1 can reorder [1,2] → matches [2,1] Group 2 has [3,4] but target needs [4,5] Only 5 is missing. Answer = 1 ⸻ 💡 What I liked about this problem: It looks like swapping. But it’s actually a graph + frequency matching problem. ⸻ Sometimes the best solution comes when you stop thinking about operations… and start thinking about what operations make possible. #LeetCode #UnionFind #Graphs #ProblemSolving #SoftwareEngineering #SDE #Java #C++ #DSA
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development