Day 87/100 🚀 | #100DaysOfDSA Solved LeetCode 345 – Reverse Vowels of a String today. Approach: Used two pointers + HashSet for fast vowel lookup. • Converted string to a char array (for in-place modification) • Maintained a HashSet of vowels (both lowercase & uppercase) • Used two pointers (left, right) Moved left forward until it finds a vowel Moved right backward until it finds a vowel • Swapped both vowels and continued Finally converted the array back to string. Time Complexity: O(n) Space Complexity: O(1) (ignoring set size as constant) Key takeaway: When checking membership frequently (like vowels), using a HashSet gives O(1) lookup, making two-pointer solutions efficient. #100DaysOfDSA #LeetCode #DSA #Java #TwoPointers #Strings #HashSet #ProblemSolving #Consistency
Reverse Vowels of a String in Java with Two Pointers and HashSet
More Relevant Posts
-
🎉🎉 Day-38 of #60DaysOfDSA 🎉🎉 Problem: Row with Maximum 1s 👉 Problem Statement: Given a 2D binary matrix (rows sorted), find the index of the row having the maximum number of 1s. 👉 Approach Used: ✔️ Traverse each row ✔️ Find first occurrence of 1 ✔️ Count number of 1s → (m - j) ✔️ Track row with maximum count 👉Time Complexity: O(n * m) #geekstreak60 #dsa #java #problemsolving
To view or add a comment, sign in
-
-
🚀 Day 83 of #100DaysOfCode Solved 3217. Delete Nodes from Linked List Present in Array on LeetCode 🔗 🧠 Key Insight: We need to remove all nodes from the linked list whose values exist in a given array 👉 Fast lookup is required → use a HashSet ⚙️ Approach (HashSet + Traversal): 1️⃣ Store all array elements in a HashSet 🔹 set.add(nums[i]) 2️⃣ Use a dummy node before head 🔹 Helps handle deletion at head easily 3️⃣ Traverse the list: 🔹 If node.next.val exists in set → delete it 👉 node.next = node.next.next 🔹 Else → move forward 4️⃣ Return dummy.next ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(m) #100DaysOfCode #LeetCode #DSA #LinkedList #HashSet #TwoPointers #Java #InterviewPrep #CodingJourney
To view or add a comment, sign in
-
-
Day 69/75 — Reverse String Simple and clean two-pointer problem. Approach: • Use two pointers (start & end) • Swap characters • Move pointers inward Key idea: while (i < j) { char temp = s[i]; s[i] = s[j]; s[j] = temp; i++; j--; } Time Complexity: O(n) Space Complexity: O(1) Basic problem, but strengthens in-place thinking and pointer control. 69/75 🔁 #Day69 #DSA #TwoPointers #Strings #Java #LeetCode
To view or add a comment, sign in
-
-
Day 41 Today’s problem: Anti-Diagonals of a Matrix The trick was noticing that elements on the same anti-diagonal have row + col = constant. Looped over all possible sums of indices and collected elements in order. Clean, simple, and efficient solution Example: Input: [[1,2],[3,4]] → Output: [1,2,3,4] Nice problem to see patterns in 2D arrays #geekstreak #Day41 #GeeksforGeeks #DSA #Java #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 73/100 🚀 | #100DaysOfDSA Solved LeetCode 219 – Contains Duplicate II today. The problem was to check if there are two equal elements in the array such that their indices differ by at most k. Approach: Used a sliding window + HashSet. • Iterated through the array while maintaining a window of size k • For each element: Checked if it already exists in the set → if yes, duplicate found within range → return true Added the current element to the set • If the set size exceeds k, removed the element that goes out of the window (nums[i - k]) This ensures we only track elements within the allowed index distance. Time Complexity: O(n) Space Complexity: O(k) Key takeaway: When constraints involve a fixed index range (k), think of using a sliding window with HashSet to efficiently track elements. #100DaysOfDSA #LeetCode #DSA #Java #SlidingWindow #HashSet #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 71 - Delete Middle Node Handling linked list traversal to identify and remove the middle node efficiently. Approach: • Traverse once to count nodes • Find middle index using n/2 • Traverse again to reach previous node • Update pointers to remove middle Key Insight: Careful handling needed when list size is small (edge cases) Time Complexity: O(n) Space Complexity: O(1) #Day71 #LeetCode #Java #CodingPractice #TechJourney #DSA #LinkedList
To view or add a comment, sign in
-
-
Day 63 - Odd Even Linked List Today’s problem was about rearranging nodes based on their positions. Approach: • Maintain two pointers → odd and even • Traverse and rearrange links in-place • Keep track of even head to attach later • Merge odd list with even list at the end Key insight: 👉 Focus on node positions, not node values. Time Complexity: O(n) Space Complexity: O(1) #Day63 #LeetCode #Java #LinkedList #CodingPractice #TechJourney #DSA
To view or add a comment, sign in
-
-
Day 61 - Add Two Numbers Worked on adding two numbers represented as linked lists. Approach: • Traverse both lists simultaneously • Add corresponding digits along with carry • Store result in a new linked list • Continue until both lists and carry are processed Key insight: Treat the linked list like a number stored in reverse order. Time Complexity: O(max(n, m)) #Day61 #LeetCode #Java #LinkedList #CodingPractice #DSA
To view or add a comment, sign in
-
-
🚀𝐃𝐚𝐲 88/100 – 𝐀𝐝𝐝 𝐁𝐢𝐧𝐚𝐫𝐲 Today’s problem was Add Binary — a great exercise to understand how addition works at the binary level. 🔍 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠: Just like decimal addition, binary addition also uses a carry, but with base 2. 💡 𝐂𝐨𝐫𝐞 𝐈𝐝𝐞𝐚: Traverse both strings from right to left Add digits along with carry Append result and update carry 𝐖𝐡𝐲 𝐢𝐭 𝐰𝐨𝐫𝐤𝐬? Binary addition rules: 0 + 0 = 0 1 + 0 = 1 1 + 1 = 0 (carry 1) ⚡ 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: Use two pointers (end of both strings) Add digits + carry Append (sum % 2) Update carry (sum / 2) Reverse the result ⏱️ 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐦𝐚𝐱(𝐧, 𝐦)) 📦 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) #Day88 #100DaysOfCode #Java #DSA #LeetCode #Strings #CodingJourney
To view or add a comment, sign in
-
-
🎉🎉 Day-32 of #60DaysOfDSA 🎉🎉 Problem: K-th Element of Two Sorted Arrays 👉 Problem Statement: Given two sorted arrays, find the element that would appear at the k-th position in the merged sorted array. 👉 Approach Used (Two Pointer / Merge Logic): ✔️ Use two pointers i and j for both arrays ✔️ Traverse like merge step of merge sort ✔️ Keep counting elements until count == k ✔️ Return the k-th element 👉 Time Complexity : O(n + m) #dsa #problemsolving #java #geekstreak60
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