Check if Strings Can Be Made Equal With Operations

✅ Day 86 of 100 Days LeetCode Challenge Problem: 🔹 #2839 – Check if Strings Can be Made Equal With Operations I 🔗 https://lnkd.in/gG4CaJpf Learning Journey: 🔹 Today’s problem involved determining if two strings can be made equal using swaps where indices differ by 2. 🔹 I observed that only certain positions can swap among themselves: • Even indices (0, 2) • Odd indices (1, 3) 🔹 Instead of simulating swaps, I directly generated possible permutations of s2 using these allowed swaps. 🔹 Then, I checked if s1 matches any of these valid transformed versions of s2. 🔹 If a match is found, return True; otherwise, False. Concepts Used: 🔹 String Manipulation 🔹 Permutations (restricted swaps) 🔹 Pattern Observation Key Insight: 🔹 Swaps are limited to positions with the same parity, meaning even and odd indices form independent groups. 🔹 This reduces the problem to checking a small set of possible rearrangements instead of brute-force simulation. Complexity: 🔹 Time: O(1) (fixed string length = 4) 🔹 Space: O(1) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories