Solved a problem where we need to check if two strings can be made equal using a special operation. The rule is: you can swap characters only if the distance between their positions is even. So basically, characters at even indices can only swap among themselves, and same for odd indices. Idea: Instead of actually swapping, I just counted characters separately for even and odd positions in both strings. If both match, then it’s possible — otherwise not. Simple concept, but interesting twist! 😊 #LeetCode #DSA #Java #ProblemSolving #CodingJourney
Checking if Strings Can Be Equal with Character Swaps
More Relevant Posts
-
🚀 Day 46/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 2315. Count Asterisks Used a boolean flag approach to track whether the current position is inside a pair of '|' and count only the valid '*' outside those sections. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening understanding of state-based string traversal and conditional counting. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 47/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 448. Find All Numbers Disappeared in an Array Used an in-place marking technique by treating indices as a hash map and marking visited numbers as negative to identify missing elements. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) (excluding output list) Strengthening understanding of array manipulation and in-place hashing tricks. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 57/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 242. Valid Anagram Used a HashMap frequency counting approach (Unicode-safe using code points) to compare character frequencies of both strings. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(n) Strengthening understanding of string frequency analysis and Unicode handling. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 62 — LeetCode Progress (Java) Problem: Merge Strings Alternately Required: Given two strings word1 and word2, merge them by alternating characters, starting from word1. If one string is longer, append the remaining characters at the end. Idea: Use two pointers to traverse both strings simultaneously and build the result step by step. Approach: Initialize two pointers for both strings. Iterate while either string still has characters: Pick one character from word1 (if available) Then pick one from word2 (if available) Continue alternating until both strings are fully traversed. Time Complexity: O(n + m) Space Complexity: O(n + m) #LeetCode #DSA #Java #Strings #TwoPointers #Algorithms #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 69/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 2103. Rings and Rods Used a 2D boolean array to track presence of colors (R, G, B) on each rod and counted rods containing all three. ⏱️ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening understanding of mapping, indexing, and state tracking techniques. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 48/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 1534. Count Good Triplets Used a brute-force triple nested loop to check all possible triplets and validate the given conditions using absolute differences. ⏱️ Time Complexity: O(n³) 📦 Space Complexity: O(1) Strengthening understanding of nested loop patterns and condition-based filtering. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Solved LeetCode 2839 – Check if Strings Can be Made Equal With Operations I today. In simple terms, we are given two strings and allowed to swap characters only at positions that are 2 indices apart (like index 0 with 2, 1 with 3). So instead of trying all swaps, the idea is to separate characters at even and odd positions and check if both strings have the same characters in those positions. If the frequency of characters matches for even and odd indices separately, then the strings can be made equal. A simple yet interesting problem that improves thinking around patterns and constraints. #LeetCode #DSA #Java #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 65/180 | #180DaysOfCode 📍 LeetCode | 💻 Java Solved: 2535. Difference Between Element Sum and Digit Sum of an Array Used a single loop + digit extraction approach to calculate both element sum and digit sum efficiently. ⏱️ Time Complexity: O(n × d) 📦 Space Complexity: O(1) Strengthening understanding of number manipulation and digit-based operations. 💪 Consistency continues 🚀 #DSA #LeetCode #Java #CodingJourney #Consistency
To view or add a comment, sign in
-
-
LeetCode — Problem 189 | Day 3 💡 Problem: Rotate Array Given an array, rotate it to the right by k steps. 🧠 My Approach: - Used reverse technique for in-place rotation - First reversed the entire array - Then reversed first k elements - Finally reversed remaining elements - Handled k using k = k % n This problem gave a good understanding of: ✔️ Array manipulation ✔️ In-place optimization (O(1) space) ✔️ Reverse logic #LeetCode #DSA #Java #CodingJourney
To view or add a comment, sign in
-
-
Day 64 - Intersection of Two Linked Lists Solved by using a two-pointer technique to find the intersection node of two linked lists. Instead of calculating lengths, both pointers traverse both lists to align automatically. Time Complexity: O(n + m) Space Complexity: O(1) #Day64 #LeetCode #Java #LinkedList #DSA #ProblemSolving #CodingJourney
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