🚀Day 96/100 #100DaysOfLeetCode 🧩Problem: Reverse Linked List II✅ 💻Language: Java 💡 Approach: 1️⃣ First, use a dummy node to handle edge cases where reversal starts at the head. 2️⃣ Traverse to the node just before the left position — call it prev. 3️⃣ Reverse the sublist between left and right using standard pointer manipulation. 4️⃣ Reconnect the reversed portion back into the original list. 🔑Key Takeaways: 🔹Dummy nodes simplify linked list edge cases. 🔹In-place reversal reduces memory overhead. 🔹Careful pointer tracking ensures list integrity. ⚙️Performance: ⏱️Runtime: 0 ms(beats 100.00%) 💾Memory: 41.29 MB(beats 70.37%) #100DaysOfLeetCode #Java #LinkedList #CodingJourney #ProblemSolving #DSA #LeetCode #CodingChallenge
Reversing a Linked List II in Java with dummy nodes and in-place reversal
More Relevant Posts
-
#Day-68) LeetCode #3228 – Maximum Number of Operations to Move Ones to the End (Java Edition) Tackled this neat string problem using a greedy approach in Java. The challenge? Move '1's to the end of the string under specific movement rules, maximizing the number of valid operations. 🧠 Core Idea: Track how many '0's we've seen and how many '1's we've already moved. Only move a '1' if there's enough '0's to justify it and the next character is also '1'. 💻 Java Strategy: Loop through the string Use counters to manage '0's and '1's Let me know how you'd tweak this or if you see a more optimal path! #Java #LeetCode #GreedyAlgorithm #StringProblems #DSA #CodingChallenge #LinkedInTech #ProblemSolving
To view or add a comment, sign in
-
-
#Day-69) LeetCode 2536: Increment Submatrices by One using a 2D difference array technique in Java — a powerful approach for handling multiple range updates efficiently. 🔧 Instead of brute-force iteration over each query, I used a prefix sum strategy to apply all updates in constant time per query, followed by a cumulative pass to build the final matrix. 🧠 Highlights: Efficient submatrix updates using difference matrix Prefix sum accumulation for final values Clean, scalable Java implementation 📌 This kind of problem is a great reminder: smart preprocessing beats brute force. Let’s connect if you’ve explored similar matrix tricks or want to brainstorm more Java optimizations! #Java #LeetCode #DSA #MatrixOptimization #CodingInPublic #ProblemSolving #TechJourney #LinkedInTech
To view or add a comment, sign in
-
-
🚀Day 99/100 #100DaysOfLeetCode 🔍Problem: Sum of Two Integers✅ 💻Language: Java 💡Approach: Instead of using the ‘+’ or ‘–’ operators, this problem leverages bit manipulation to perform addition. 🔸Use XOR (^) to calculate the sum without carry. 🔸Use AND (&) followed by a left shift (<< 1) to calculate the carry. 🔸Repeat until no carry remains. 📚Key Takeaways: 🔹Reinforced understanding of bitwise operations. 🔹Learned how addition can be simulated using logical operations. 🔹Improved understanding of low-level arithmetic computation. ⚡Performance: ⏱️Runtime: 0 ms (Beats 100.00%) 💾Memory: 40.88 MB (Beats 10.05%) #100DaysOfLeetCode #Java #BitManipulation #CodingChallenge #ProblemSolving #DSA #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
The Subtle Trap of Optional in Java 💭 Optional was meant to prevent NullPointerException but misuse can make code worse! ❌ Returning Optional from setters ❌ Using Optional fields in entities ❌ Serializing Optional with Jackson (it’ll break your JSON mapping) ✅ Correct use: Method return types to signal absence of value. Example: Optional<User> user = userRepository.findByEmail(email); user.ifPresent(System.out::println); 💭 Have you seen Optional abused in your codebase? #Java #CleanCode #BestPractices
To view or add a comment, sign in
-
-
💡 Java Logical Program Practice — Remove Duplicates & Find Largest Numbers 💻 Today I practiced a simple yet powerful Java logic: ✅ Removed duplicate elements from an array using the Set interface ✅ Found the largest and second largest numbers using loops Concepts used: Array sorting (Arrays.sort()) Set for duplicate removal Loop logic for max & second max values Output: Before remove duplicate: [1, 2, 2, 3, 5, 6, 7, 8, 9, 12, 13, 14, 14, 15] After remove duplicate: [1, 2, 3, 5, 6, 7, 8, 9, 12, 13, 14, 15] Largest number: 15 Second largest number: 14 🧠 This kind of daily logic practice strengthens core Java understanding and logical thinking! #Java #CoreJava #CodingPractice #JavaDeveloper #ProgrammingLogic #ProblemSolving #SetInterface #Array #DailyLearning #LearningInPublic
To view or add a comment, sign in
-
-
🚀 #100DaysOfDSA — Day 26/100 Topic: Arrays as Function Arguments in Java 💻 💡 What I Did Today: Today, I learned how arrays can be passed as arguments to functions in Java — and how changes made inside a function affect the original array. This concept is super important for understanding how references work in Java! ⚙️ 🧠 Logic Used: Defined an update() function that increases every array element by 1. Passed the marks[] array into the function. Observed that updates inside the function reflected in the original array — proving arrays are passed by reference (not by value). 📊 Output: Before update → 66 68 72 68 74 After update → 67 69 73 69 75 ✨ Takeaway: Today’s practice gave me clarity on how data moves between methods in Java. Understanding references helps avoid unexpected behavior and write cleaner, safer code 💡 #100DaysOfCode #Day26 #Java #DSA #Arrays #ProblemSolving #CodingJourney #LearnInPublic #CodeNewbie #DeveloperLife
To view or add a comment, sign in
-
-
: 🚀 Day 83 — Small Java Detail, Big Difference While solving the LRU Page Replacement problem, I learned something interesting about Java’s remove() method. In Java, remove() behaves differently depending on what we pass — it can remove by position or by value. This tiny detail made a big difference in my logic! It reminded me that even small concepts can completely change the program’s behavior. Learning these little things step by step feels great ✨ #VenkatToSDEin90Days #Java #LearningInPublic #DSA #OperatingSystems
To view or add a comment, sign in
-
-
Week 8 || Day 2💡 Reversing words in Java — step by step! Today I practiced reversing each word in a sentence using two different approaches: 🔹 Approach 1 — With .reverse() method: Split the sentence using split(" ") to separate words. Used StringBuffer for each word and applied .reverse() directly. Joined the reversed words back with spaces. 🔹 Approach 2 — Without using .reverse(): Again split the string into words. For each word, used a for loop running from the last character to the first. Appended each character manually into a new StringBuffer. Combined the reversed words carefully, avoiding extra spaces.⚡ #Java #StringBuffer #ProgrammingLogic #JavaFullStack
To view or add a comment, sign in
-
🚀 Day 23 of 100 Days of LeetCode 📘 Problem: Reverse Integer 💻 Language: Java ✅ Status: Accepted (Runtime: 1 ms ⚡ — Beats 81.9%) Today’s challenge focused on reversing digits of an integer while handling overflow cases carefully. It was a great reminder that even simple-looking problems test your precision and edge-case thinking. ✨ Key Takeaways: Integer limits can silently cause overflow errors 🧮 Learned how to handle Integer.MIN_VALUE and MAX_VALUE properly Small logic tweaks can make or break your runtime Every accepted submission adds a new layer of understanding 💪 #Day23 #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #SoftwareDevelopment #DSA #KeepLearning #CodeEveryday
To view or add a comment, sign in
-
-
Today I explored, how sorting works in Java 8 using Lambdas and Streams. Here what I learned, List.of() creates an immutable list, so we can't modify it directly. If we want to do any modification on immutable list, we can 1. Create a mutable list List<Integer> immutableList = List.of(5, 8, 3, 2, 7, 1); List<Integer> mutableList = new ArrayList<Integer>(immutableList); mutableList.sort((a, b) -> a.compareTo(b)); 2. By using streams, can get new modified list. List<Integer> immutableList = List.of(5, 8, 3, 2, 7, 1); List<Integer> sortedList = immutableList.stream(). sorted(). collect (Collectors.toList); So, streams in Java 8 are non-mutating, they create a new result instead of modifying original data source. It feels great to understand the subtle differences between mutating (list.sort()) operations and functional operations (stream().sorted()). #Java #Java8 #Streams #Lambdas #CodingJourney #LearningEveryday #SoftwareDevelopment
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