🚀 Day 3 / 100 – #100DaysOfCode Today’s focus was on Java backend fundamentals and deep DSA understanding. ⸻ 🔧 Development (Java) 📌 Local DB using JSON • Used JSON as a lightweight local database • Applied Java Serialization to convert objects ↔ JSON • Linked serialized JSON data with Java classes for persistent storage • Helpful for small-scale apps where a full DB is overkill 🧠 DSA Progress 1️⃣ Set Matrix Zeroes Problem: If an element is 0, set its entire row and column to 0 Optimized Approach (O(1) Space): • Use first row & first column as markers • If matrix[i][j] == 0: • Mark matrix[i][0] = 0 • Mark matrix[0][j] = 0 • Maintain two flags: • rowZero → whether first row contains 0 • colZero → whether first column contains 0 • Traverse matrix (excluding first row/column) and update based on markers • Finally, update first row & column using flags 2️⃣ Word Search Problem: Check if a word exists in a 2D board Approach: • Start DFS from cells matching first character • Move in 4 directions (up, down, left, right) • Use backtracking: • Mark cell as visited • Revert after recursive call • Stop early if index exceeds word length or characters mismatch. 3️⃣ Find the Duplicate Number Problem: Find the single duplicate in an array of size n+1 Efficient Approach (Index Marking): • For each element x: • Go to index abs(x) • If value at that index is already negative → duplicate found • Else, mark it negative My solution links- https://lnkd.in/gf4b-E6K https://lnkd.in/gNv9gtgB https://lnkd.in/gGatDNSK 📌 Consistency > Motivation. Building logic daily, one problem at a time. #100DaysOfCode #Day3 #Java #DSA #ProblemSolving #LeetCode #BackendDevelopment #LearningInPublic #SoftwareEngineer #Consistency #PlacementPrep
Java DSA Fundamentals and Problem Solving with LeetCode Solutions
More Relevant Posts
-
🚀 Day 25 of my DSA Journey (LeetCode + Java) Today’s practice focused on frequency-based problems, using HashMaps, Priority Queues, and simple array traversal. Each question had a different flavor but all were fun to solve! ✅ Problems Solved Today: LC 347 – Top K Frequent Elements LC 451 – Sort Characters by Frequency LC 414 – Third Maximum Number 🧠 My Experience Solving These: 🔸 347. Top K Frequent Elements A classic frequency + heap problem. First, I created a HashMap to count occurrences Then pushed elements into a max-heap/min-heap based on frequency Extracted the top k frequent elements This problem is a great example of how HashMap + PriorityQueue together give an optimal O(n log k) solution. 🔸 451. Sort Characters by Frequency This was a fun problem because it combines strings with frequency sorting. My steps: Count frequency using HashMap Use a max-heap to sort characters by highest frequency Build the final string by repeating each character its number of times Very satisfying to see the string rearranged cleanly based on frequencies. 🔸 414. Third Maximum Number This one was the simplest among the three. I used a single pass approach: Track the largest, second largest, and third largest values Update them as we scan through the array Return the third max or highest max if not enough distinct numbers exist No sorting needed — an O(n) solution with clean logic. 📌 Key Takeaway Today: Frequency-based problems are powerful and appear everywhere. ✔ HashMap is the backbone ✔ PriorityQueue/Heap helps extract top elements ✔ Many problems reduce to counting + ordering ✔ Always aim for O(n log k) or O(n) instead of sorting everything Feeling more confident every day! On to Day 26! 🚀 #DSA #LeetCode #Java #SlidingWindow #ProblemSolving #CodingJourney #Consistency #LearningDaily
To view or add a comment, sign in
-
Day 11: Scope & Memory – Mastering the 3 Types of Variables in Java 🧠📍 Today was all about understanding where data "lives" within my code. I learned that in Java, where you declare a variable completely changes its life cycle and how it can be accessed. Here is my breakdown of the three types of variables: 1. Local Variables (The Temporary Workers) ⏱️ These are declared inside a method. Access: They can only be used within that specific method. Memory: They are created when the method starts and destroyed once it finishes. Key Rule: They do not get default values; you must initialize them before use! 2. Instance Variables (The Object’s Properties) 🏠 These are declared inside the class but outside any method. Access: To access these, you must create an object (Instance) of the class. Memory: Every object gets its own separate copy of these variables. If I change the value in Object A, Object B remains unchanged. 3. Static Variables (The Shared Knowledge) 🌐 These are declared inside the class, outside methods, with the static keyword. Access: You can access them directly using the Class Name—no object is required! Memory: There is only one copy shared across all objects of that class. If one object changes a static variable, it changes for everyone. My Takeaway: Understanding Variable Scope is my first real step into Memory Management. It’s not just about storing data; it’s about knowing exactly where that data is accessible! #JavaFullStack #CoreJava #CodingJourney #VariableScope #MemoryManagement #Day11 #LearningInPublic 10000 Coders Meghana M
To view or add a comment, sign in
-
Java☕ — Generics🎯 I used to think generics were just for avoiding casting. #Java_Code List<String> list = new ArrayList<>(); But the real learning was this: Generics provide compile-time type safety. Without generics: #Java_Code List list = new ArrayList(); list.add("Ajay"); list.add(10); // no error With generics: #Java_Code List<String> list = new ArrayList<>(); list.add(10); // compile error 📝Then I learned about wildcards: ✅? extends T → read only ✅? super T → write allowed 📝Golden rule that clicked for me: PECS — Producer Extends, Consumer Super. Generics are not syntax sugar. They’re about writing safer, reusable APIs. #Java #AdvancedJava #Generics #BackendDevelopment
To view or add a comment, sign in
-
JVM (Java Virtual Machine) – How Java Actually Runs Your Code Today I revised the internal workflow of the JVM and understood how .class files are loaded, verified, executed, and managed in memory. 1. Class Loader Subsystem Responsible for bringing .class files into memory. It has three main loaders: -->Bootstrap ClassLoader – loads core Java classes -->Extension ClassLoader – loads extension libraries -->Application ClassLoader – loads user-defined classes After loading, JVM performs: -->Verification – checks bytecode safety -->Preparation – allocates memory for static fields -->Resolution – replaces symbolic references -->Initialization – runs static blocks and static variables 2. Runtime Data Areas JVM internally divides memory into: -->Method Area: class code, static data, metadata -->Heap: objects + instance variables -->Stack: method calls + local variables (per thread) -->PC Registers: next instruction of each thread -->Native Method Stack: C/C++ code used via JNI 3. Execution Engine -->Handles actual execution: -->Interpreter: line-by-line execution -->JIT Compiler: converts hotspots into machine code for speed -->Garbage Collector: frees unused memory 4. Native Method Interface (JNI) Allows Java to interact with native libraries (C/C++). Understanding the JVM is essential to writing efficient, memory-safe Java code. Thanks Prasoon Bidua sir for making JVM fundamentals easy to grasp. #Java #JVM #CoreJava #MemoryManagement #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Today I went through an interesting backend concept — HashMap Collision (Java) ❓ Question Why do collisions happen in HashMap, and how does Java handle them (Java 8)? --- ⚠️ The Problem — What is Collision? HashMap internally stores data in an array of buckets. Whenever a key is inserted, Java calculates: index = hash(key) % array_size Since the array size is limited (16, 32, 64…), different keys can sometimes generate the same index. Example: hash("CAT") = 18 hash("DOG") = 10 array_size = 8 18 % 8 = 2 10 % 8 = 2 Both keys go to index 2 → Collision occurs. --- 🧠 Understanding Hash A hash is simply a numeric value generated from a key using a hash function, helping the system quickly decide where the data should be stored. --- ✅ The Solution — How Java 8 Handles Collisions When multiple keys map to the same bucket: 1️⃣ First entry is stored normally 2️⃣ Next entries are stored using a LinkedList in that bucket 3️⃣ If entries become large (≈ 8), LinkedList converts into a Red-Black Tree for faster search Why this matters: - LinkedList search → O(n) - Tree search → O(log n) So even with many collisions, performance remains efficient. --- 📌 Final Insight HashMap performance depends heavily on hashing + bucket indexing. Collisions are normal, but Java smartly optimizes them using LinkedList → Tree conversion to maintain speed. #BackendLearning #Java #HashMap #SpringBoot #SoftwareEngineering #LearningInPublic #JavaDeveloper #cfbr
To view or add a comment, sign in
-
-
Java☕ — HashMap vs ConcurrentHashMap clarified 🔥 Earlier, I thought: “HashMap works fine… why another map?” Then I learned about multi-threading. #Java_Code Map<String, Integer> map = new HashMap<>(); ❌ Not thread-safe #Java_Code Map<String, Integer> map = new ConcurrentHashMap<>(); ✅ Thread-safe The difference is not syntax — it’s behavior. 📌HashMap 📝Faster 📝Unsafe in multi-threading 📌ConcurrentHashMap 📝Thread-safe 📝Uses bucket-level locking 📝No ConcurrentModificationException Big realization for me: Thread safety is not optional in real applications. If multiple threads touch shared data — design matters. #Java #ConcurrentHashMap #Multithreading #BackendDevelopment #LearningJava
To view or add a comment, sign in
-
Java☕ — HashMap vs ConcurrentHashMap clarified 🔥 Earlier, I thought: “HashMap works fine… why another map?” Then I learned about multi-threading. #Java_Code Map<String, Integer> map = new HashMap<>(); ❌ Not thread-safe #Java_Code Map<String, Integer> map = new ConcurrentHashMap<>(); ✅ Thread-safe The difference is not syntax — it’s behavior. 📌HashMap 📝Faster 📝Unsafe in multi-threading 📌ConcurrentHashMap 📝Thread-safe 📝Uses bucket-level locking 📝No ConcurrentModificationException Big realization for me: Thread safety is not optional in real applications. If multiple threads touch shared data — design matters. #Java #ConcurrentHashMap #Multithreading #BackendDevelopment #LearningJava
To view or add a comment, sign in
-
🚀 Day 14 – Array vs ArrayList in Java (Key Differences & Why Arrays Still Matter) Why learn Array when we already have ArrayList? 🤔 At first I thought: “Why bother learning arrays when ArrayList exists?” But the truth is… 👉 You can’t master ArrayList without mastering Array first. Understanding data structures is a must for writing efficient Java programs. Today I compared Array and ArrayList and learned why arrays are still very important. 🧠 Why Array is Important? ✅ Foundation of all data structures ✅ Used internally by ArrayList, HashMap, etc. ✅ Faster access (O(1)) ✅ Less memory usage ✅ Works with primitive types (int, double, etc.) ✅ Best choice for performance-critical code 💡 When to use what? ✔ Use Array → When size is fixed & performance matters ✔ Use ArrayList → When size changes frequently & flexibility is needed 🔥 Final Thought Master arrays first. Advanced collections become easy automatically. #Day14 #Java #Array #ArrayList #DSA #JavaDeveloper #LearningJourney #ProgrammingBasics #Consistency
To view or add a comment, sign in
-
Problem of the Day: Minimum Absolute Difference (LeetCode) Today I tackled the classic Minimum Absolute Difference problem. The goal is simple yet elegant: . Given an array of integers, find all pairs with the smallest absolute difference. Here’s my clean and efficient Java solution: ...................................................................................................................................................... class Solution { public List<List<Integer>> minimumAbsDifference(int[] arr) { Arrays.sort(arr); int min=Integer.MAX_VALUE; for(int i=1;i<arr.length;i++){ min=Math.min(min,(arr[i]-arr[i-1])); } List<List<Integer>> l=new ArrayList<>(); for(int i=1;i<arr.length;i++){ if((arr[i]-arr[i-1])==min){ l.add(Arrays.asList(arr[i - 1], arr[i])); } } return l; } } ........................................................................................................................................................ Key Takeaways: Sorting simplifies the problem by ensuring differences are checked only between consecutive elements. A two-pass approach (first to find the minimum difference, second to collect pairs) keeps the logic clear and modular. Time complexity: O(n log n) due to sorting, which is optimal here. ✨ Solving problems like these sharpens algorithmic thinking and prepares us for real-world scenarios where efficiency matters. #Java #LeetCode #ProblemSolving #CodingChallenge #DataStructuresAndAlgorithms
To view or add a comment, sign in
-
🔹 1. What is the difference between abstract class and interface? • Abstract class = can have methods with code • Interface = only method declarations (Java 8+ allows default methods) 🧩 Example: Abstract class = blueprint + some instructions Interface = only instructions ⸻ 🔹 2. What is instanceof keyword? Checks if an object is of a specific type. 🔍 Example: “Is this animal a Dog?” → yes/no ⸻ 🔹 3. What is try-with-resources? Automatically closes resources like files or streams. 🧹 Example: Like washing your hands after cooking — automatic cleanup. ⸻ 🔹 4. What is enum in Java? Enum = list of predefined constants. 🎨 Example: Days of the week = MONDAY, TUESDAY, … enum Days { MONDAY, TUESDAY, WEDNESDAY } ⸻ 🔹 5. Difference between throw and throws? • throw → actually throws an exception • throws → declares that a method might throw an exception 🚨 Example: Throw = “I am throwing the ball” Throws = “I may throw the ball sometime” ⸻ 🔹 6. What is volatile keyword? Ensures variable is visible across all threads. 🧵 Example: Shared whiteboard in class — everyone sees the latest update. ⸻ 🔹 7. What is synchronized? Controls access to a method or block so only one thread can execute at a time. 🚦 Example: Traffic signal — only one car goes at a time. ⸻ 🔹 8. Difference between HashMap and Hashtable? • HashMap = non-synchronized, allows null keys • Hashtable = synchronized, no null keys 🧺 Example: Basket (HashMap) = casual use Vault (Hashtable) = safe but strict ⸻ 🔹 9. What is transient keyword? Prevents a variable from being saved during serialization. 🔒 Example: Secret password you don’t want to store in files. ⸻ 🔹 10. What is Java Reflection? Allows inspecting classes, methods, and fields at runtime. 🪞 Example: Looking at yourself in a mirror and seeing what you have. ⸻ 🔹 11. Difference between Stack and Queue? • Stack → LIFO (Last In, First Out) • Queue → FIFO (First In, First Out) 🍽 Example: Stack = stack of plates Queue = line of people at a ticket counter #Java #JavaDeveloper #JavaInterview #JavaProgramming #CoreJava #CodingInterview #ProgrammingLife
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