• Day 93 – LeetCode #389: Find the Difference • Problem: Given two strings s and t, where t is s with one extra character added at a random position, find that extra character. • Approach: – Created a HashMap to store the frequency of each character in t. – Iterated through s and decreased the corresponding counts in the map. – The character with a remaining count of 1 is the extra character. – Used getOrDefault() to simplify frequency counting. • Key Insight / Learning: Frequency maps are a versatile tool for string problems involving counts or differences. Using HashMap efficiently handles character counting and helps solve problems in linear time. • Complexity: – Time: O(n + m) where n = s.length(), m = t.length() – Space: O(k) where k = number of unique characters (≤ 26 for lowercase letters) • Solution Link: https://lnkd.in/gtvv5CDd #LeetCode #Java #Coding #ProblemSolving #HashMap #DataStructures #CompetitiveProgramming #Programming #DailyCoding #CodeDaily #SoftwareEngineer #LearnToCode
LeetCode #389: Find Extra Character in String
More Relevant Posts
-
🔥 Day 71 of my LeetCode Journey 🔥 📘 Problem: 219. Contains Duplicate II 🎯 Difficulty: Easy 🔹 Problem Statement: Given an integer array nums and an integer k, determine whether there exist two distinct indices i and j such that nums[i] == nums[j] and |i - j| ≤ k. 🔹 Learning: This problem is a great practice for understanding the sliding window technique with HashSet. By maintaining a window of size k and storing elements in a set, we can efficiently detect duplicates within the allowed range. The approach ensures: O(n) time complexity O(k) extra space Clean and optimized logic without nested loops 💡 Strengthened my understanding of window-based problem solving and efficient use of hash-based data structures! #LeetCode #DSA #ProblemSolving #Java #100DaysOfCode #CodingJourney #Programming #LogicBuilding
To view or add a comment, sign in
-
-
Day 13 Problem Statement: You’re given an array squares where each element is: [some x‑coordinate, some y‑coordinate, side length l] Each triple describes an axis‑aligned square on the 2D plane. The goal is to find the lowest possible y‑value of a horizontal line such that: The total area above the line equals The total area below the line Important rule: Overlapping areas are counted multiple times — i.e., if two squares overlap, the overlapped region contributes to the total for each square individually. Approach : The problem is to find a horizontal line that splits all squares into equal areas above and below. To solve it: Calculate the total area of all squares. Use binary search on y-coordinate to find the line. For each candidate y, sum the area below the line for all squares (full square if below, 0 if above, partial if intersecting). Move the line up or down depending on whether the area below is less or more than half the total. Stop when the areas are balanced — that y is the answer. #HappyCoding #LeetCode #Coding #ProblemSolving #Programming #Java #SoftwareEngineering #DSA #DataStructures #Algorithms #CompetitiveProgramming #CodeNewbie #TechLearning #DailyCodingChallenge #BinarySearch #LearnToCode #DeveloperCommunity
To view or add a comment, sign in
-
📐 Jagged Arrays. A jagged array means: ✅ Different rows can have different number of columns ✅ int[][] arr = new int[rows][]; → only rows fixed ✅ each row can have different columns ✅ arr[i].length will be different for different rows GitHub Link: https://lnkd.in/g6JtkYCA 🔖Frontlines EduTech (FLM) #Java #Arrays #DeepCopy #ShallowCopy #2DArray #JavaProgramming #Coding #DSA #ProgrammingBasics #LearnJava #CodeSnippet
To view or add a comment, sign in
-
-
DAY 29 – Invert Tree + Symmetric Tree You’ll learn: ✔ Swapping left & right children ✔ Mirror comparison logic ✔ Simple & elegant recursion patterns 🌳 Problem 1: Invert Binary Tree Level: Easy Platform: LeetCode 226 Invert means: 4 4 / \ --> / \ 2 7 7 2 / \ / \ / \ / \ 1 3 6 9 9 6 3 1 🔹 Java Code class Solution { public TreeNode invertTree(TreeNode root) { if (root == null) return null; // swap children TreeNode temp = root.left; root.left = root.right; root.right = temp; // recurse on both subtrees invertTree(root.left); invertTree(root.right); return root; } } 🔹 Explanation Swap left & right children at every node Then recursively invert subtrees Simple top-down recursion Time: O(n) Space: O(h) recursion #DSA #DataStructuresAndAlgorithms #Coding #Programmer #LeetCode #CodeEveryday #JavaDSA #CodingPractice #ProblemSolving #CP #CompetitiveProgramming #DailyCoding #TechJourney #CodingCommunity #DeveloperLife #100DaysOfCode #CodeWithMe #LearnToCode #GeekForGeeks #CodingMotivation
To view or add a comment, sign in
-
Day 14/100 – LeetCode Challenge ✅ Problem: #1048 Longest String Chain Difficulty: Medium Language: Java Approach: Dynamic Programming with Memoization & Preprocessing Time Complexity: O(n × L²) where n = words, L = word length Space Complexity: O(n) Key Insight: A word chain is formed if we can add one letter anywhere to predecessor. Preprocess by grouping words by length for efficient predecessor search. Use DFS + memoization to find longest chain for each word. Solution Brief: Mapped words by length for quick access. For each word, tried removing each character to find predecessors. Recursively computed chain length with memoization (dp map). Building word connections through character manipulation. #LeetCode #Day14 #100DaysOfCode #DynamicProgramming #Java #Algorithm #CodingChallenge #ProblemSolving #LongestStringChain #MediumProblem #Memoization #StringManipulation #DSA #HashMap
To view or add a comment, sign in
-
-
Day 472 of my #500DaysOfCode challenge 🚀 ✅ LeetCode 3453: Separate Squares I (Medium) 📌 Problem Summary: We are given multiple squares on a 2D plane, each defined by bottom-left coordinate (x, y) and side length (l). The task is to find the minimum y-coordinate of a horizontal line such that: ✅ Total area above the line = Total area below the line ⚠️ Important note: Squares may overlap, and overlapping area should be counted multiple times (each square contributes independently). 💡 Key Insight: For any horizontal line y = mid, each square contributes to the area below based on how much of its height lies below the line: If the line is below the square → contributes 0 If the line is above the square → contributes full area l² If the line cuts the square → contributes l * (mid - y) Since the area below increases monotonically as the line moves upward, we can apply: ✅ Binary Search on the y-coordinate 🎯 Goal: Find smallest y where areaBelow(y) ≥ totalArea / 2. ⚡ Complexity: ✅ Time: O(n log range) (binary search iterations × n squares) ✅ Space: O(1) This was a great problem to reinforce how binary search can be used beyond arrays, especially when the function is monotonic 📈. #leetcode #dsa #java #binarysearch #programming #problemsolving #500daysofcode #consistency #learning
To view or add a comment, sign in
-
-
🚀 LeetCode 961 | N-Repeated Element in Size 2N Array | Potd 2nd jan. A clean reminder that simple logic + right data structure = instant wins✅ Key takeaways: Use a HashSet to track seen elements. The first duplicate you encounter is the answer — no extra passes needed. Elegant, readable, and interview-safe. Why this matters: Reinforces hashing fundamentals. Teaches you to spot problems where early exit is possible. Classic example of trading a bit of space for optimal time. Complexity: ⏱ Time: O(n) (beats 100%) 🧠 Space: O(n) (beats 50%) Sometimes the best solutions aren’t fancy — they’re just correct, fast, and clean. DSA isn’t about showing off, it’s about thinking straight. 💡 #LeetCode #DSA #Java #HashSet #ProblemSolving #CodingInterview #Algorithms #CleanCode #SoftwareEngineering #DailyCoding #TechCareers #Programming
To view or add a comment, sign in
-
-
🚀 Day 48 of My Daily Coding Challenge 🚀 Today I implemented In-Place Merge Sort using Recursion — focusing on sorting the array without creating new subarrays. 📌 What I worked on: • Dividing the array using start, mid, and end indices • Recursively sorting left and right halves • Merging both halves back within the same array using a temporary buffer • Careful index handling to avoid extra space overhead 💡 Key Learning: Understanding how indices flow in recursion is crucial for writing efficient, in-place algorithms. This approach strengthened my grasp of divide-and-conquer logic and memory handling. 🔗 Solution (Java):[https://lnkd.in/dBM-nBCC] #100DaysOfCode #Day48 #Java #DSA #MergeSort #InPlaceAlgorithm #Recursion #ProblemSolving #CodingJourney #LearnInPublic
To view or add a comment, sign in
-
🚀 Day 45 of #100DaysOfCode Solved LeetCode Problem #1411 – Number of Ways to Paint N × 3 Grid 🎨 This problem focused on counting valid colorings of an N × 3 grid such that no two adjacent cells (horizontally or vertically) have the same color. The challenge was to recognize repeating patterns and optimize the solution using dynamic programming. Key Learnings: -> Broke the problem into two repeating pattern states (2-color & 3-color combinations) -> Derived recurrence relations to transition between rows -> Used constant space DP for optimal performance -> Reinforced how mathematical observation simplifies complex DP problems Language Used: Java -> Runtime: 2 ms (Beats 99.49%) -> Memory: 42.06 MB Dynamic programming becomes powerful when patterns are clearly identified 🚀 #LeetCode #DynamicProgramming #Java #ProblemSolving #100DaysOfCode #DSA
To view or add a comment, sign in
-
-
🚀 Day 90/100 - Problem of the day :- Number of Ways to Paint N x 3 Grid. 🎯 Goal Efficiently compute the total number of valid ways using dynamic programming with modular arithmetic. 💡 Core Idea Use DP with two state arrays to build results iteratively, applying recurrence relations and modulo to handle large values. 🔑 Key Takeaway Breaking a problem into well-defined states makes complex counting problems manageable and scalable. 📦 Space Complexity: O(n) ⏱️ Time Complexity: O(n) #LeetCode #DynamicProgramming #Java #ProblemSolving #DSA #CodingJourney #Consistency #100DaysChallenge
To view or add a comment, sign in
-
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