Day 1/100 Problem Solved : Two Sum – LeetCode (Easy) Problem Statement: Given an array of integers and a target value, return the indices of the two numbers such that they add up to the target. -> Approach Used: Implemented a nested loop to check all possible pairs Compared the sum with the target Returned the indices once the condition matched Ensured not to use the same element twice 🔹 Example: Input: [2, 7, 11, 15], Target: 9 Output: [0, 1] This problem strengthened my understanding of: Arrays Looping concepts Index handling Basic problem-solving logic in Java Consistent practice on coding platforms helps improve logical thinking and prepares for technical interviews. Looking forward to solving more problems and improving every day! #Java #LeetCode #ProblemSolving #CodingPractice #DataStructures #SoftwareDevelopment #LearningJourney
Two Sum Problem Solution in Java on LeetCode
More Relevant Posts
-
Day 17 of #100DaysOfCode Today I worked on Binary Search (LeetCode 704) — a classic and powerful algorithm every developer should master. What I learned: How binary search reduces time complexity to O(log n) Importance of working on sorted arrays How to efficiently divide the search space using start, end, and mid Writing clean and optimal Java code for real interview scenarios Key takeaway: Instead of checking every element (O(n)), binary search helps us eliminate half of the data in each step — making it super fast and efficient. Problems like these remind me that understanding the logic is more important than just coding the solution. Consistency is the goal, improvement is the result. #Day17 #100DaysOfCode #Java #DataStructures #Algorithms #BinarySearch #CodingJourney #LeetCode
To view or add a comment, sign in
-
-
🚀 Mastering Java Through LeetCode 🧠 Day 2 I’m continuing my journey of solving problems from the LeetCode 75 list to strengthen my Data Structures and Algorithms (DSA) skills using Java. Consistency in problem-solving is helping me improve logical thinking and prepare for real-world software engineering interviews. 📌 LeetCode problem solved today: Q. 1071 – Greatest Common Divisor of Strings 📝 Problem Summary: For two strings s and t, we say t divides s if s is formed by repeating t multiple times. 👉 The goal is to find the largest string x that divides both str1 and str2. 💡 Key Insight: ✔️ If (str1 + str2).equals(str2 + str1) → a common pattern exists ✔️ Then the answer is based on GCD of lengths 💻 Key Java concepts practiced: ✔️ String concatenation & comparison ✔️ Pattern recognition in strings ✔️ Recursion (GCD using Euclidean algorithm) ✔️ Substring operations ✔️ Combining math with programming logic Takeaway: This problem shows how combining Mathematical concepts (GCD) with String manipulation can lead to efficient solutions. #Java #DSA #LeetCode #ProblemSolving #CodingJourney #JavaDeveloper #TechSkills #LearningInPublic #CodingPractice #SoftwareEngineering #Developers #CodingLife
To view or add a comment, sign in
-
-
🚀 Day 38 of #100DaysOfLeetCode Today I solved "Container With Most Water" problem on LeetCode. 🔹 Difficulty: Medium 🔹 Concept Used: Two Pointer Technique 🔹 Language: Java 📌 Problem Summary: Given an array representing heights of vertical lines, the goal is to find two lines that together with the x-axis can contain the maximum amount of water. 💡 Approach: Instead of checking all possible pairs (O(n²)), I used the Two Pointer approach which reduces the time complexity to O(n). Steps: 1️⃣ Start with two pointers at the beginning and end of the array. 2️⃣ Calculate the area using the smaller height. 3️⃣ Move the pointer with the smaller height inward. 4️⃣ Track the maximum area during each step. 📊 Result: ✅ Runtime: 5 ms (Beats 81.86%) ✅ Memory: Beats 95.54% This problem was a great exercise to understand optimization using two pointers instead of brute force. Consistency is the key — moving forward one problem at a time! 💪 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 𝗗𝗮𝘆 12 𝗼𝗳 𝗖𝗼𝗻𝘀𝗶𝘀𝘁𝗲𝗻𝗰𝘆 — Solved “Valid Anagram” on LeetCode Today I worked on a classic string problem: Valid Anagram — a great question to strengthen understanding of frequency counting and optimized string handling. 🔍 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 Given two strings s and t, determine whether t is an anagram of s. 👉 Anagram means both strings contain the same characters with the same frequency. 🧠 𝗕𝗿𝘂𝘁𝗲 𝗙𝗼𝗿𝗰𝗲 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 Sort both strings Compare them ⏱ Time Complexity: O(n log n) 👉 Works fine but not optimal for interviews ⚡ 𝗢𝗽𝘁𝗶𝗺𝗶𝘇𝗲𝗱 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 (Used Today) Instead of sorting, I used frequency counting with arrays. ✅ 𝗦𝘁𝗲𝗽𝘀: If lengths are different → return false Create two arrays of size 26 (for lowercase letters) Count frequency of characters in both strings Compare both frequency arrays 💻 𝗖𝗼𝗱𝗲 𝗜𝗻𝘀𝗶𝗴𝗵𝘁 Increment count for characters in s Increment count for characters in t Compare both arrays → if all values match → anagram ✅ 📌 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 s = "anagram" t = "nagaram" ✔ Same frequency → Valid Anagram ⏱ 𝗖𝗼𝗺𝗽𝗹𝗲𝘅𝗶𝘁𝘆 𝗔𝗻𝗮𝗹𝘆𝘀𝗶𝘀 Time: O(n) Space: O(1) (constant size array) 💡 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 Always try to replace sorting with counting when dealing with characters Frequency array is a powerful optimization technique Writing clean and optimal code improves both performance and interview confidence Grateful for continuous learning and growth 🙏 Consistency is the real game changer 💯 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #100DaysOfCode #TechLearning #SoftwareDevelopment
To view or add a comment, sign in
-
-
🚀 Day 538 of #750DaysOfCode 🚀 Today I solved Flip Square Submatrix Vertically (LeetCode 3643) using Java. 🔹 Problem Summary: Given a matrix and a square submatrix defined by top-left corner (x, y) and size k, we need to flip that square vertically. Flipping vertically means reversing the order of rows inside the selected k × k submatrix while keeping the rest of the matrix unchanged. 🔹 Approach Used: I used a two-pointer approach to swap rows inside the square: • One pointer at the top row • One pointer at the bottom row • Swap elements column by column inside the square • Move pointers towards the center This way, the submatrix gets flipped vertically in-place without extra space. 🔹 Key Concepts Learned: ✅ Matrix traversal ✅ Submatrix manipulation ✅ Two-pointer technique ✅ In-place swapping ✅ Clean implementation in Java Small problems like this help in mastering matrix operations, which are very common in coding interviews. #750DaysOfCode #Day538 #LeetCode #Java #DSA #Algorithms #CodingChallenge #Matrix #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
🚀 Week 8 – Java + DSA Journey Update This week was all about strengthening my problem-solving skills and diving deeper into Data Structures using Java. 💻 🔹 What I focused on: Arrays & Advanced Array Problems Two Pointer Technique Sliding Window Concepts Solved multiple problems on LeetCode 🔹 Key Learnings: Learned how to optimize brute force solutions into efficient ones (O(n)) Understood real use of two pointers in problems like pair sum & sorting-based questions Sliding window made problems like longest substring much more efficient 🔹 Challenges faced: Some problems looked easy but required deep thinking to optimize. Debugging logic took time, but consistency helped 💪 🔹 Progress: Improved coding speed ⏱️ Better understanding of patterns instead of just memorizing solutions 📌 Goal for next week: Start Linked List Practice medium-level problems consistently Consistency is the only key 🔑 #Java #DSA #LeetCode #CodingJourney #SoftwareEngineering #LearningInPublic
To view or add a comment, sign in
-
-
From implementing basic arrays to building my own Generic ArrayList from scratch in Java 🚀 Recently, in an interview, I was asked to implement an ArrayList with major operations. Instead of stopping there, I took it as a challenge and went deeper. Here’s what I built: ✔ Dynamic resizing (handled capacity growth) ✔ Generic support using <T> ✔ add(element) and add(index, element) ✔ remove(index) with shifting ✔ get(index) with boundary checks ✔ size() and capacity() methods ✔ Custom toString() for clean output Along the way, I also understood an important concept: 👉 Why Java doesn’t allow new T[] (due to type erasure) 👉 How real ArrayList internally uses Object[] This wasn’t just about coding — it was about understanding how data structures actually work internally. Small improvements daily → big progress over time. #Java #DataStructures #DSA #CodingInterview #Learning #Consistency
To view or add a comment, sign in
-
-
\🚀 Day 15 of My LeetCode Journey 🧩 Problem Solved: 1980. Find Unique Binary String 💻 Language: Java Today I worked on a problem where we are given n unique binary strings, each of length n, and we need to find another binary string of length n that does not exist in the list. 🔍 Key Insight: Instead of checking all possible binary combinations, we can build a new string by flipping the i-th bit of the i-th string. This guarantees the new string will differ from every string in the array at least at one position. ⚡️ Concept Used: Diagonalization technique 📈 Time Complexity: O(n) 📦 Space Complexity: O(n) 💡 This problem reminded me that sometimes the smartest solutions come from simple observations rather than brute force approaches. Consistency is key — solving problems daily to strengthen my Java and problem-solving skills. #LeetCode #Java #CodingJourney #ProblemSolving #100DaysOfCode #DataStructures #LearningInPublic
To view or add a comment, sign in
-
-
Day 2 of my #365DaysCodingChallenge | CodeOjas Journey Today, I solved 3 interesting array-based problems using Java: 🔹 Unique Subarray Sum Pairs – Found pairs of subarrays with equal sums using hashing techniques. 🔹 Array Rotation – Rotated array efficiently using optimized reversal approach. 🔹 Shifted Array – Implemented element shifting with proper handling of wrap-around using modular arithmetic. 💡 Approach: Focused on breaking problems into smaller parts, using concepts like subarrays, indexing, and optimization techniques. ⚡ Complexity: Most solutions were optimized to O(n) time with minimal space. 📌 Takeaway: Strong understanding of array manipulation and problem breakdown is key to solving DSA problems efficiently. Building consistency and improving every day 💪🔥 📂 Code: [Your GitHub Link] #DSA #Java #CodeOjas #365DaysOfCode #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
LeetCode 1593 – Split a String Into the Max Number of Unique Substrings An ideal problem to understand Backtracking. The task is simple but tricky: Split a string into substrings such that all substrings are unique, and maximize the number of splits. 🚀 Approach (Backtracking) 1. Start from index i and try every possible substring s[i...j]. 2. If the substring is not already used (checked using a HashSet), we: add it to the set recursively explore the remaining string starting from j + 1 3. Each recursive call increases the current split count. 4. When we reach the end of the string (i >= length), we update the maximum number of unique splits. 5. After recursion, we remove the substring from the set (backtrack) so other possibilities can be explored. # Core Backtracking Pattern Choose → Explore → Undo Choose: Add substring to the set Explore: Recurse for the remaining string Undo: Remove substring to try other partitions Backtracking explores all possible partitions, but the HashSet ensures no substring repeats, giving the maximum valid split. Perfect example of how recursion + state tracking can systematically search the solution space. #LeetCode #Backtracking #Java #DSA #CodingInterview #Recursion
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