🚀 DSA in Java | Shortest Path Using NSEW Directions 🚀 While practicing Data Structures & Algorithms in Java, I solved a classic logic problem: 👉 Finding the shortest path after a sequence of directions (N, S, E, W). 📌 Problem Insight: Given a string consisting of directions: N (North) S (South) E (East) W (West) We track movement on a 2D plane starting from (0, 0) and calculate the shortest distance from the origin after completing the full path. 🧠 Approach Used: Maintain two variables x and y for horizontal and vertical movement Traverse the string once Update coordinates based on direction Final shortest path = |x| + |y| (Manhattan Distance) ⚙️ Complexity: Time Complexity: O(n) Space Complexity: O(1) 💡 What I learned from this problem: ✅ Translating real-world movement into code ✅ Coordinate system fundamentals ✅ Importance of absolute values in distance calculation ✅ Writing optimized and readable Java logic I’m consistently practicing DSA in Java to improve problem-solving skills and build a strong foundation for backend and system-level development. 📈 Learning Focus: Core Java DSA fundamentals Logic building Writing optimized solutions One problem at a time, getting better every day 💻🔥 #DSA #Java #ProblemSolving #LearningInPublic #CodingJourney #JavaDeveloper #DataStructures #Algorithms #100DaysOfCode #BackendDevelopment
Java DSA: Shortest Path with NSEW Directions
More Relevant Posts
-
🚀 Day 50/100 – #JavaJourney Continuing the journey with a mix of DSA practice and Core Java learning. Today’s focus was revisiting some important LeetCode problems and strengthening Java fundamentals. 🧠 DSA Practice (LeetCode) 1️⃣ LC 1 – Two Sum (Hash Map Complement Approach) 2️⃣ LC 26 – Remove Duplicates from Sorted Array (Two Pointer Approach) 3️⃣ LC 35 – Search Insert Position (Linear / Binary Search Approach) 4️⃣ LC 27 – Remove Element (Two Pointer Approach) 5️⃣ LC 283 – Move Zeroes (Two Pointer + Swap / Write Approach) 6️⃣ LC 66 – Plus One Also progressing with Prefix Sum concepts, practicing problems like Subarray Range Sum and Maximum Subarray to better understand array patterns. 📚 Core Java Concepts Studied 1️⃣ Enums & Annotations 2️⃣ Functional Interfaces & Lambda Expressions 3️⃣ Exception Handling & Custom Exceptions 4️⃣ User Input Handling (BufferedReader & Scanner) 5️⃣ Multithreading Concepts (Threads, Runnable, Race Condition, Thread States) 📈 Key Takeaways • Revisiting classic problems helps reinforce important DSA patterns • Learning concepts like lambdas and multithreading adds deeper understanding of Java • Consistency with both DSA practice and Java fundamentals is helping me build stronger foundations 💻 Check out my work: 🔗 GitHub: https://lnkd.in/gGquYtVZ 🔗 LeetCode: https://lnkd.in/gaNyep3M Day 50 completed ✅ Halfway through the journey and still learning every day 🚀 #Java #DSA #LeetCode #CoreJava #Multithreading #Lambda #100DaysOfCode #CodingJourney #Consistency #ProblemSolving
To view or add a comment, sign in
-
🚀 Day 2/30 – Java DSA Challenge 🔎 Problem 10: 2016. Maximum Difference Between Increasing Elements (LeetCode – Easy) Solved another interesting array problem today 🔥 This problem is similar to the stock profit problem but with a slight twist. 🧠 Problem Statement Given an integer array nums, find the maximum difference: nums[j] - nums[i] Such that: ✔ 0 ≤ i < j < n ✔ nums[i] < nums[j] If no such pair exists → return -1. 💡 Example Input: [7,1,5,4] Best choice: Buy at 1 Sell at 5 Maximum Difference = 4 ✅ 👨💻 Approach (Greedy – Single Pass) ✔ Maintain the minimum value seen so far ✔ For each element: Calculate difference = current − minimum Update maximum difference ✔ Update minimum value if smaller element is found ✔ If no valid increasing pair → return -1 ⏱ Time Complexity: O(n) – Single traversal of the array 📦 Space Complexity: O(1) – No extra data structures used 📌 Key Learning: Maintaining a running minimum helps solve many array-based optimization problems efficiently. Day 2 progress continues strong 💪🔥 Small improvements daily → Big growth over time 🚀 #Day2 #30DaysOfCode #Java #DSA #LeetCode #ArrayProblems #GreedyAlgorithm #CodingJourne
To view or add a comment, sign in
-
-
🚀 DSA in Java – Day 75 Today I solved the Remove Linked List Elements problem on LeetCode. 🔹 Problem Statement: Given the head of a linked list and an integer val, remove all nodes of the linked list that have Node.val == val, and return the new head. 🔹 My Approach: I used an iterative traversal technique with two pointers: temp → to traverse the linked list prev → to keep track of the previous node Steps: 1️⃣ Traverse the linked list using a loop. 2️⃣ If the current node value equals val, remove that node. 3️⃣ Handle the special case when the head node itself needs to be deleted. 4️⃣ Continue until the end of the list. 🔹 Key Learning: Handling edge cases in Linked Lists (especially when deleting the head node). Proper use of previous and current pointers. Strengthening my understanding of Linked List traversal. Consistency is the key to mastering Data Structures & Algorithms. One step closer to becoming a better problem solver! 💻 #DSA #Java #LeetCode #LinkedList #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 2/30 – Java DSA Challenge 🔎 Problem 8: 121. Best Time to Buy and Sell Stock (LeetCode – Easy) Solved another important array problem today 🔥 This is a classic interview question focused on greedy approach and array traversal. 🧠 Problem Statement You are given an array prices where prices[i] represents the stock price on the ith day. You need to: ✔ Buy one stock ✔ Sell it on a future day ✔ Maximize profit If no profit is possible → return 0. 💡 Example Input: [7,1,5,3,6,4] Buy at price = 1 Sell at price = 6 Profit = 5 ✅ 👨💻 Approach (Greedy + Single Pass) ✔ Track the lowest price seen so far ✔ For each day: Calculate profit = current price − lowest price Update maximum profit ✔ Update lowest price if a smaller value appears This ensures we always buy before we sell. ⏱ Time Complexity: O(n) – Single traversal of the array 📦 Space Complexity: O(1) – No extra data structures used 📌 Key Learning: Greedy algorithms work efficiently when we make the best decision at each step without revisiting previous states. Day 2 progressing strong 💪 Consistency builds confidence 🚀 #Day2 #30DaysOfCode #Java #DSA #LeetCode #ArrayProblems #GreedyAlgorithm #CodingJourney
To view or add a comment, sign in
-
-
Day 25 Today Learning Journey in Advanced Java Today I explored several powerful concepts in Advanced Java that are essential for writing clean, efficient, and scalable applications. Here’s what I learned: 🔹 Comparator Interface Learned how to customize sorting logic using Comparator, including sorting based on different fields and using lambda expressions for cleaner code. 🔹 Multithreading Understood how threads work in Java, how to create them using Runnable, and why synchronization is important to avoid race conditions. 🔹 Collections Framework Deepened my understanding of core collection types like ArrayList, HashSet, and LinkedHashSet, and how they differ in terms of ordering and performance. 🔹 Stream API Explored functional programming concepts in Java using: filter() – for conditional data selection map() – for transforming data reduce() – for aggregating results The Stream API really changed the way I think about data processing in Java — more readable, concise, and powerful. #Java #AdvancedJava #Multithreading #Collections #StreamAPI #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
My Journey to Becoming a Better Java Problem Solver Every strong Java developer starts from zero — not knowing DSA, struggling with logic, and feeling confused by errors. I was there too. Here’s how I’m building my problem-solving skills in Java, step by step Step 1: Strong Java Basics I focused on Core Java concepts like: Variables, loops, conditionals OOP (Encapsulation, Inheritance, Polymorphism, Abstraction) A strong base makes every problem easier. Step 2: Learn Data Structures Started with simple ones: Arrays & Strings Linked Lists, Stack, Queue Then moved to: HashMap, Trees, Graphs Step 3: Algorithms & Logic Practiced: Searching & Sorting Recursion Greedy & Dynamic Programming Step 4: Daily Problem Solving Consistency matters more than speed: 2–3 problems daily Platforms like LeetCode &GeeksforGeeks focus on thinking, not just solutions Step 5: Think Like an Interviewer Optimizing time & space complexity Explaining my approach clearly Writing clean readable Java code From struggling with basic loops to solving structured DSA problems — the journey is real slow and totally worth it. 👉 If you’re starting from zero, don’t give up. Every advanced Java developer was once a beginner. #JavaDeveloper #ProblemSolving #DSA #Java #Placements #LearningJourney #Coding
To view or add a comment, sign in
-
🚀 Back to Java — Recalling the Fundamentals for DSA! Lately, I’ve been revisiting core Java basics to strengthen my foundation for Data Structures & Algorithms. Sometimes, going back to fundamentals is the fastest way to move forward. Here are a few key refreshers I focused on: ✅ Operator Precedence – Understanding how expressions actually execute (Java’s version of BODMAS). ✅ String Handling – Difference between == vs .equals() and how the String Pool works. ✅ Type Casting – Why (double) is needed to avoid integer division issues. ✅ Bitwise Operators – Quick recap on |=, ^=, <<, >> and their real use cases. ✅ Concatenation & Formatting – Mixing numbers with strings and writing cleaner outputs. 💡 One thing I’m realizing again: Strong DSA skills start with strong language fundamentals. Now continuing the journey toward deeper DSA practice and problem solving 🔥 #Java #DSA #CodingJourney #Programming #Learning #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 29 / 180 – DSA with Java 🚀 📘 Topic Covered: Arrays & Two-Pointer Technique 🧩 Problem Solved: Container With Most Water Problem: Given an array where each element represents the height of a vertical line, find two lines that together with the x-axis form a container that holds the maximum amount of water. Approach: Used a two-pointer strategy starting from both ends of the array. Calculated the water area using the shorter height and the distance between pointers, then moved the pointer with the smaller height to try finding a better container. Key Learning: ✔️ Efficient use of two-pointer technique ✔️ Understanding how pointer movement impacts optimization ✔️ Reducing brute-force O(n²) solutions to O(n) If you’re also preparing for DSA, let’s connect and learn together 🤝 #DSA #Java #180DaysOfCode #LearningInPublic #Arrays #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
📘 Java Fundamentals: Data Types & Number Systems 🚀 While strengthening my Java foundation, I focused on how data is actually stored and processed at the system level — not just writing code, but understanding what happens underneath. Here’s what I revised 👇 🔹 Memory Basics 1 byte = 8 bits Data type is that converts real world data into binary format All data is ultimately stored as 0s and 1s Transistors: HIGH voltage = 1, LOW voltage = 0 🔹 Yes / No Type Data boolean → true / false Core of decision-making in programs Powers if, else, loops, and logical conditions 🔹 Integer Data Types (Java) byte → 1 byte → -128 to 127 short → 2 bytes → -32,768 to 32,767 int → 4 bytes → -2,147,483,648 to 2,147,483,647 long → 8 bytes → use L / l 🔹 Real Numbers float → single precision (32-bit) double → double precision (64-bit) Precision matters when handling decimals 🔹 Binary Logic 1’s & 2’s complement Representation of negative numbers 🔹 Characters & Encoding ASCII vs Unicode char in Java uses 2 bytes 🔹 Number Systems Decimal → no prefix Octal → 0 Hexadecimal → 0x Binary → 0b 💡 Key takeaway: Strong fundamentals lead to efficient, reliable code. Frameworks change, but core concepts don’t. Building step by step. 🚀 TAP Academy #Java #DataTypes #Boolean #ProgrammingBasics #ComputerScience #LearningJourney #SoftwareDevelopment #TapAcademy
To view or add a comment, sign in
-
-
🚀 Day 6/30 – Java DSA Challenge 🔎 Problem 46: 704. Binary Search (LeetCode – Easy) Today I revised one of the most fundamental and important algorithms in DSA — Binary Search 🔥 🧠 Problem Summary Given: A sorted array nums (ascending order) A target value 🎯 Return the index of the target if found Otherwise return -1 ⚠️ Required Time Complexity: O(log n) 💡 Key Insight Since the array is sorted, we can: ✅ Eliminate half of the search space in every step. That’s the power of Binary Search. 🔄 Approach 1️⃣ Initialize two pointers: low = 0 high = n - 1 2️⃣ While low <= high: Find mid If arr[mid] == target → return mid If arr[mid] < target → search right half Else → search left half 3️⃣ If not found → return -1 ⏱ Time Complexity O(log n) 📦 Space Complexity O(1) 📌 Pattern Used ✔ Divide and Conquer ✔ Binary Search on Sorted Array ✔ Logarithmic Search Optimization 🎯 Key Learning Always use safe mid calculation: mid = low + (high - low) / 2 (prevents integer overflow) Binary Search is the foundation for: Lower Bound / Upper Bound Search in Rotated Array Peak Element First/Last Occurrence Search on Answer problems 🔥 46 Problems Completed Day 6 = Strong fundamentals reinforced 💪 Master basics → Master advanced problems 🚀 #Day6 #30DaysOfCode #Java #DSA #LeetCode #BinarySearch #InterviewPrep #ProblemSolving #Consistency
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