š„ Day 2 of my 50 Days Wild Coding Kickoff! š„ š” Problem 2: Two Sum Given an array of integersĀ numsĀ and an integerĀ target, return the indicesĀ iĀ andĀ jĀ such thatĀ nums[i] + nums[j] == targetĀ andĀ i != j. You may assume thatĀ everyĀ input has exactly one pair of indicesĀ iĀ andĀ jĀ that satisfy the condition. Return the answer with the smaller index first. š Approach: Used a HashMap to store elements and efficiently find the complement in one pass (O(n) time complexity). š§ Key Idea: For each element nums[i], check if target - nums[i] already exists in the map. If yes ā solution found! #100DaysOfCode #50DaysOfCode #CodingChallenge #JavaDeveloper #JavaProgramming #DataStructures #Algorithms #DSA #CodingJourney #CodeNewbie #ProgrammerLife #TechLearning #DeveloperLife #CodingDaily #InterviewPrep #LeetCode #ProblemSolving #SoftwareDeveloper #CodePractice #LearnToCode #TechSkills #FutureDeveloper #CodingMotivation #BuildInPublic #Consistency #GrowthMindset #DevelopersIndia #CodeWithMe #DailyCoding
Two Sum Problem Solution with HashMap
More Relevant Posts
-
DSA Journey Continues š Today I solved the āProduct of Array Except Selfā problem on LeetCode. This problem really helped me understand how to optimize without using division and extra space. Problem Goal: For each index, return the product of all elements except the current one. Step-by-Step Approach : 1. Left Product Pass Traverse from left to right Store product of all elements before current index Keep updating a variable left 2. Right Product Pass Traverse from right to left Multiply with product of all elements after current index Maintain another variable right Core Idea: First pass ā store left products Second pass ā multiply with right products Final array gives the result Why This is Efficient: No division used Time Complexity: O(n) Space optimized (no extra arrays, only output array) What I Learned Today: Prefix and suffix product concepts How to solve problems in two passes Writing optimized solutions without extra space Understanding patterns like this makes problem solving much easier over time. #Day4 #DSAJourney #Java #LeetCode #ProblemSolving #Coding #Learning #Consistency #100DaysOfCode 10000 Coders Pathulothu Navinder
To view or add a comment, sign in
-
š Day 6 of LeetCode Problem Solving Solved todayās problem ā LeetCode #1480: Running Sum of 1d Array š»š„ ā Approach: Prefix Sum (Running Sum) ā” Time Complexity: O(n) š Space Complexity: O(n) The task was to compute the running sum of an array where each element represents the sum of all previous elements including itself. š Example: Input: [1,2,3,4] Output: [1,3,6,10] š” Key Idea: Keep adding elements as you traverse the array and store the cumulative sum. š Core Logic: Initialize sum = 0 Traverse array Add current element ā sum += nums[i] Store in result array š” Key Learning: Simple problems help build strong fundamentals ā mastering basics like prefix sum is very important for advanced problems. Grateful to my mentor Pulkit Aggarwal ā your guidance is helping me strengthen my fundamentals every day š Consistency is the key ā small steps lead to big results š #Day6 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
š Day 8 of 30 Days Coding Challenge Today I solved a problem on LeetCode: Minimum Distance Between Three Equal Elements. š Approach: Initially implemented a brute-force solution using three nested loops (O(n³)). It worked for smaller constraints but highlighted the importance of optimizing. š” Key Learning: Instead of checking all possible triplets, grouping indices of identical elements and analyzing consecutive occurrences leads to a much more efficient solution. ā” Optimization Insight: Reduced time complexity from O(n³) ā O(n) Leveraged HashMap to store indices and process only relevant combinations. š Takeaway: This problem reinforced an important concept: š When dealing with repeated elements, think in terms of grouping and patterns rather than brute force. Consistency is key ā learning something new every day and improving step by step. #Day8 #30DaysOfCode #CodingChallenge #LeetCode #Java #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnToCode #TechGrowth
To view or add a comment, sign in
-
-
Day 55 of 100 Days of LeetCode š» Today I solved Longest Consecutive Sequence ā and honestly, this one taught me more about coding discipline than algorithms. At first, my approach was correct: Used HashSet for O(1) lookup Applied the āstart of sequenceā logic But I still got TLE. The reason? A tiny mistake: if(!set.contains(num-1)); That single ; made my condition useless and turned my O(n) solution into O(n²). š” Lesson learned: Donāt just think your logic is right ā verify what your code actually does Small syntax mistakes can completely break optimal solutions Debugging is just as important as problem-solving Finally fixed it and got Accepted ā Slowly improving not just in DSA, but in writing cleaner and more careful code. #100DaysOfLeetCode #DSA #Java #CodingJourney #Learning
To view or add a comment, sign in
-
-
š Day 7 of LeetCode Problem Solving Solved todayās problem ā LeetCode #414: Third Maximum Number š»š„ ā Approach: Tracking Top 3 Maximums ā” Time Complexity: O(n) š Space Complexity: O(1) The challenge was to find the third distinct maximum number in an array. If it doesnāt exist, return the maximum number. š Instead of sorting (which takes extra time), I tracked the top 3 distinct maximum values in a single pass. š” Key Idea: Maintain three variables (max, smax, tmax) to store the first, second, and third maximum values while traversing the array. š Core Logic: Skip duplicates Update max, second max, third max accordingly If third max doesnāt exist ā return max š” Key Learning: Optimizing from sorting to a single-pass solution can significantly improve efficiency. Grateful to my mentor Pulkit Aggarwal ā your guidance is helping me think more optimally š Consistency is the key ā improving step by step š #Day7 #LeetCode #DSA #Java #CodingJourney #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
š Solved LeetCode Problem #47 ā Permutations II Today I tackled a classic backtracking problem that adds an interesting twistāhandling duplicate elements while generating permutations. š Problem Insight: Given an array that may contain duplicates, the goal is to generate all unique permutations without repetition. š” Approach Used: I used a Backtracking + Sorting strategy: First, sort the array to bring duplicates together Use a visited[] array to track used elements Apply a smart condition to skip duplicate choices during recursion This ensures that we only generate distinct permutations efficiently. š§ Key Learning: Handling duplicates in recursive problems is crucial Sorting helps simplify duplicate detection Backtracking becomes powerful when combined with pruning conditions š Complexity: Time: O(n!) Space: O(n) ⨠This problem strengthened my understanding of: Backtracking techniques Recursion control and pruning Writing optimized solutions for combinatorial problems Consistency in solving such problems is helping me build stronger problem-solving skills every day! šŖ #LeetCode #DSA #Backtracking #Algorithms #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
-
Day-3 of My Coding Journey Today I worked on the LeetCode problem: š Find Numbers with Even Number of Digits What I learned: How to count digits in a number using String.valueOf(num).length() How to check if a number has even digits using % 2 == 0 ā My Mistake: I wrote: String.value(num).length % 2 == 0 ā Issues: Used value() instead of valueOf() Forgot () in length ā Fix: String.valueOf(num).length() % 2 == 0 After correcting this, my solution got Accepted! ⨠Takeaway: Small syntax mistakes can cause errors, but fixing them improves attention to detail and strengthens fundamentals. #Day3 #LeetCode #Java #CodingJourney #Learning 10000 Coders
To view or add a comment, sign in
-
-
š Day 50 of My Coding Journey Todayās problem was simple but interesting: š Replace all 0ās in a number with 5 Example: Input: 1004 Output: 1554 š” Approach: Traverse each digit of the number Whenever a digit is 0, replace it with 5 Reconstruct the number š§ Key Learning: Even easy problems improve thinking about edge cases and number manipulation. Consistency matters more than difficulty. š„ 50 days completed ā not stopping here. Next target: Day 100 šÆ #Day50 #CodingJourney #Java #ProblemSolving #Consistency #Learning My way ===== class Solution { Ā Ā int convertfive(int num) { Ā Ā Ā Ā int l=0,sum=0; Ā Ā Ā Ā String s=""+num,s1="",s2=""; Ā Ā Ā Ā for(int i=0;i<s.length();i++) Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā if(s.charAt(i)=='0') Ā Ā Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā Ā Ā s1=s1+'5';Ā Ā Ā Ā Ā Ā Ā } Ā Ā Ā Ā Ā Ā else Ā Ā Ā Ā Ā Ā { Ā Ā Ā Ā Ā Ā Ā Ā s1=s1+s.charAt(i); Ā Ā Ā Ā Ā Ā } Ā Ā Ā Ā } Ā Ā Ā Ā for(int i=0;i<s1.length();i++) Ā Ā Ā Ā { Ā Ā Ā Ā Ā s2=""+s1.charAt(i); Ā Ā Ā Ā Ā Ā l=Integer.parseInt(s2); Ā Ā Ā Ā Ā sum=(sum*10)+l; Ā Ā Ā Ā } Ā Ā Ā Ā return sum; Ā Ā } }
To view or add a comment, sign in
-
-
š Day 13 / 50 ā Wild Coding Kickoff š„ Todayās problem looked like it wanted a complicated solution⦠but it ended up teaching me something much simpler. I read the question and instantly thought: āOkay, substring search⦠this might get tricky.ā š Loops, comparisons, edge cases⦠my mind started going there. But then I stopped and asked: š āIs there a simpler way?ā Thatās when I used this: class Solution { public int strStr(String haystack, String needle) { int index = haystack.indexOf(needle); return index; } } š” What does indexOf() actually do? It searches for the first occurrence of needle inside haystack Returns: ā The starting index if found ā -1 if the substring is not present š„ Example haystack = "sadbutsad" needle = "sad" š Output: 0 (because "sad" starts at index 0) š§ What I learned today Sometimes we try to prove we know everything⦠But real skill is knowing when to keep things simple. Using built-in methods effectively is also a skill. #Day13 #50DaysOfCode #WildCodingKickoff #LeetCode #Java #CodingJourney #Consistency #KeepItSimple #ProblemSolving
To view or add a comment, sign in
-
-
š Day 13/100 ā LeetCode Journey š Problem: Rotate Array (LeetCode 189) Todayās problem looked simple at first⦠but it taught me something deeper about how arrays and math work together. š¹ Task: Rotate an array to the right by k steps. Example: [1,2,3,4,5,6,7], k = 3 ā [5,6,7,1,2,3,4] --- š” Key Learning: Instead of shifting elements again and again (which is inefficient), I learned a smarter way using: š "(i + k) % n" This single formula helped me: - Move elements to the correct position - Avoid index out-of-bounds - Understand how modulo (%) creates a circular effect --- š§ Biggest takeaway: At first, I struggled with: š Why "3 % 7 = 3" š Why we donāt use decimals in modulo Now it finally makes sense: ā Modulo gives the remainder after full division ā It helps wrap values within array limits ā Arrays can be treated like a circle š --- š» Approach Used: - Extra array to store rotated values - Place each element using "(i + k) % n" - Copy back to original array --- ⨠What I realized: Sometimes the problem isnāt coding⦠Itās understanding the math behind it. --- #Day13 #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving
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
Your an other tech geek in my connection!!