Java Problem Solving: Maximum Number of String Pairs with HashSet

🚀 Day 87 – #100DaysOfCode Today I solved a problem on Maximum Number of String Pairs using HashSet. 🔹 Problem: Given an array of strings, find the number of pairs where one string is the reverse of another. 🔹 Approach I Used: Traverse through each word in the array. Reverse the current string using StringBuilder. Check if the reversed string already exists in a HashSet. If it exists → we found a pair ✅ Otherwise → store the current word in the set. 💡 Key Idea: Using a HashSet allows constant time lookup O(1) to quickly check if the reverse string already appeared. ⚡ Time Complexity: O(n) ⚡ Space Complexity: O(n) #DSA #Java #CodingJourney #LeetCode #ProblemSolving #100DaysOfCode

  • graphical user interface, text, application

To view or add a comment, sign in

Explore content categories