🚀 Day 55 of My Python & DSA Journey Back at it again on LeetCode—and today’s problem was all about recognizing patterns in strings 🔍 Problem Solved: Group Anagrams Grouped words that are anagrams of each other by using a hashmap (dictionary) and a clever trick—sorting each string to create a unique key. 💡 Words with the same sorted form belong to the same group, making it efficient to cluster anagrams together. ⚡ Key Learnings: • Strengthened understanding of hashmaps (dictionaries) • Learned how to use sorting as a key technique • Improved skills in string manipulation • Practiced grouping and organizing data efficiently 📊 Complexity: Time Complexity: O(n × k log k) Where: • n = number of strings • k = length of each string For each string, we sort it to form a key. Sorting takes O(k log k), and we do this for all n strings. Total Time Complexity = O(n × k log k) Space Complexity: O(n × k) We store all input strings in a hashmap (grouped by sorted keys). Each string contributes up to k characters Total Space Complexity = O(n × k) Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day55 #Python #LeetCode #DSA #Algorithms #CodingJourney #100DaysOfCode 10000 Coders🚀
Python LeetCode Day 55: Group Anagrams with Hashmap
More Relevant Posts
-
🚀 Solved: Group Anagrams Problem (LeetCode) Today I worked on an interesting problem — grouping anagrams efficiently using Python. 💡 Approach: I used a hashmap (dictionary) where: The key is the sorted version of each word The value is a list of words (anagrams) matching that key Example: "eat", "tea", and "ate" → all become "aet" after sorting → grouped together 🧠 Key Insight: Sorting each string gives a unique identifier for all its anagrams. ⚙️ Time Complexity: Sorting each word takes O(k log k) For n words → O(n * k log k) 📦 Space Complexity: O(n * k) for storing grouped anagrams ✅ Result: Accepted ✔️ Runtime: 5 ms (faster than ~99% submissions) 📈 Growth & Consistency: Improving step by step by solving problems daily and focusing on writing clean and optimized code. Small consistent efforts are helping me build stronger problem-solving skills and deeper understanding of DSA. 🔁 Staying consistent is the real game changer! #Python #DSA #LeetCode #Coding #ProblemSolving #Consistency #Growth #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 61 of My Python & DSA Journey Today I solved LeetCode 2089 — Find Target Indices After Sorting Array, a problem that focuses on counting and understanding sorting behavior efficiently. 🔍 Problem Solved: Given an array and a target value, return the indices of the target after sorting the array in non-decreasing order. 💡 Approach Used: Instead of actually sorting the array, I used an optimized counting approach: • Count numbers less than target • Count numbers equal to target • Generate indices based on these counts This avoids sorting and improves efficiency. ⚡ Key Learnings: • Optimizing without sorting • Counting-based logic • Understanding index positioning after sorting • Writing efficient solutions 📊 Complexity Analysis: ✅ Time Complexity: O(n) Single pass through the array ✅ Space Complexity: O(1) Only storing count variables 🎯 Why This is Efficient? Instead of sorting (O(n log n)), we solved it in linear time O(n). Under the Guidance of: Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day61 #Python #LeetCode #DSA #Algorithms #CodingJourney #100DaysOfCode #10000Coders 🚀
To view or add a comment, sign in
-
-
🚀 Day 62 of My Python & DSA Journey Today’s LeetCode problem was Ugly Number (263) — a simple yet interesting problem focused on number factorization. 🔍 Problem Solved: An Ugly Number is a positive number whose prime factors only include 2, 3, and 5. The task was to check whether a given number is an ugly number or not. 💡 Approach Used: • Keep dividing the number by 2, 3, and 5 • Remove all these factors • If the final number becomes 1, it's an ugly number • Otherwise, it's not ⚡ Key Learnings: • Understanding prime factorization • Using while loops effectively • Writing clean and efficient logic • Improving number-based problem solving 📊 Complexity Analysis: ✅ Time Complexity: O(log n) We continuously divide the number by 2, 3, and 5 ✅ Space Complexity: O(1) No extra space used 🎯 Why This is Efficient? Instead of checking all factors, we directly remove allowed prime factors, making the solution fast and clean. Under the Guidance of: Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day62 #Python #LeetCode #DSA #Algorithms #CodingJourney #100DaysOfCode 10000 Coders 🚀
To view or add a comment, sign in
-
-
Day 49 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the Equilibrium Index of an array. An equilibrium index is an index where the sum of elements on the left is equal to the sum of elements on the right. What the program does: • Takes an array as input • Finds an index where left sum = right sum • Returns the index if found • Returns -1 if no such index exists How the logic works: • Calculate the total sum of the array • Initialize left_sum = 0 • Traverse the array using enumerate() • For each element: – Right sum = total_sum - left_sum - current element – If left_sum == right_sum, return the index • Add the current element to left_sum • If no equilibrium index is found, return -1 Example: Input: [-7, 1, 5, 2, -4, 3, 0] Output: 3(Left sum = Right sum = 1) Another example: Input: [1, 2, 3] Output: -1 (No equilibrium index) Another example: Input: [1, 0, -1] Output: 1 Why this approach is efficient: – Uses prefix sum concept – Avoids nested loops – Time Complexity: O(n) Key learnings from Day 49: – Understanding prefix sums – Optimizing from brute force to O(n) – Working with running totals – Strengthening array problem-solving #100DaysOfCode #Day49 #Python #PythonProgramming #Arrays #PrefixSum #Algorithms #DataStructures #ProblemSolving #CodingPractice #InterviewPrep #LearnByDoing #ProgrammingJourney #DeveloperGrowth #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
Ever tried to "fix" a value inside a `for` loop while zipping, only to find the original list unchanged? 🤔 Let's break down why. This is a classic Python iterator deep dive. When you zip lists, you create an iterator yielding tuples. The loop variable is just a reference to the current tuple element, not a pointer back into the list. **Key Mechanics:** - `zip()` produces an immutable tuple for each iteration. - Reassigning the loop variable simply points that variable to a new object; it does not mutate the original list. - The loop variable is a local name within the loop's scope, separate from the list's indices. **Takeaway:** To modify the original list, you need to access it by index, or use a list comprehension/map. Direct assignment to the iteration variable only rebinds the name. Understanding this distinction between names, references, and mutability is crucial for mastering Python's data model. It’s not a bug—it’s a feature of clean, predictable iteration. #Python #ProgrammingLogic #MorningCode #SoftwareEngineering #TechDeepDive What’s a similar "aha!" moment you’ve had with iterators or variable scoping?
To view or add a comment, sign in
-
Day 43 of my #100DaysOfCode challenge 🚀 Today I worked on a Python program to find the Longest Common Prefix (LCP) among a list of strings. This is a popular problem that helps strengthen string manipulation and comparison logic. What the program does: • Takes a list of strings as input • Finds the common starting characters shared by all strings • Returns the longest common prefix • Handles edge cases like empty lists and single strings How the logic works: • If the list is empty, return an empty string • Sort the list of strings • Compare only the first and last strings (they will have the maximum difference) • Iterate character by character • Add matching characters to the prefix • Stop when characters don’t match • Return the final prefix Example: Input: ["flower", "flow", "flight"] Output: "fl" Another example: Input: ["dog", "racecar", "car"] Output: "" (No common prefix) Another example: Input: ["apple", "apricot", "april"] Output: "ap" Why this approach works well: – Sorting reduces comparisons to just two strings – Efficient and easy to implement – Time Complexity: O(n log n + m) Key learnings from Day 43: – String comparison techniques – Using sorting to simplify problems – Handling edge cases effectively – Writing optimized and clean logic #100DaysOfCode #Day43 #Python #PythonProgramming #Strings #Algorithms #ProblemSolving #CodingPractice #DataStructures #InterviewPrep #LearnByDoing #DeveloperGrowth #ProgrammingJourney #ComputerScience #BTech #CSE #AIandML #VITBhopal #TechJourney
To view or add a comment, sign in
-
-
🔍 Day 36 of My Problem Solving Journey Today I explored one of the most important concepts in strings — Searching & Finding. In Python, we often use methods like: ✔️ find() → to get the index of a substring ✔️ in → to check existence ✔️ index() → similar to find but throws error if not found But instead of just using built-in functions, I tried to understand the internal logic behind searching 👇 Find the position of a substring without using built-in functions. 🧠 My Approach: Traverse the string Compare characters one by one Return index if match is found Return -1 if not found def my_find(s, sub): for i in r print(my_find("manuuuu", "u")) # Output: 3 ✨ What I learned: How searching works internally Difference between find() and index() Importance of logic building instead of relying on built-ins 📈 Small steps every day = Big growth over time! #Day36 #Python #CodingJourney #ProblemSolving #100DaysOfCode #Learning #Developers #Programming Rudra Sravan kumar
To view or add a comment, sign in
-
-
Day 2 of my LeetCode journey 🚀 Today’s problem: Group Anagrams This challenge was all about grouping strings that share the same characters. I approached it using a dictionary + hashing strategy in Python. For each word, I sorted its characters and used that as a key (converted into a tuple), ensuring all anagrams map to the same bucket. Here’s the core logic I implemented: ▪️Traverse the list of strings ▪️Sort each string → convert to tuple → use as dictionary key ▪️Append original string to the corresponding group ▪️Finally, return all grouped values This approach keeps the implementation clean and scalable. Time Complexity: ▪️Sorting each string takes O(k log k) (where k = length of string) ▪️For n strings → O(n * k log k) overall Space Complexity: ▪️O(n * k) for storing grouped anagrams A solid step forward in understanding how hashing + transformations can simplify complex grouping problems. Staying consistent and leveling up daily 💪 #LeetCode #Day2 #Python #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 57 of My Python & DSA Journey Today I solved Search Insert Position using Binary Search — a classic problem that strengthens problem-solving and optimization skills! 🔍 Problem Solved: Search Insert Position Given a sorted array and a target value, return the index if the target is found. If not, return the position where it should be inserted. 💡 Approach Used: Used Binary Search to efficiently find the correct position in O(log n) time instead of scanning the entire array. ⚡ Key Learnings: • Strengthened Binary Search concepts • Learned how to handle insert positions • Improved understanding of sorted arrays • Practiced writing optimal solutions 📊 Complexity Analysis: Time Complexity: O(log n) Binary search halves the search space in every iteration. Space Complexity: O(1) No extra space used, only variables. 🎯 Code Strategy: • Initialize left and right pointers • Find mid index • Compare with target • Adjust search range • Return correct insert position Consistency is the key — one problem closer to mastering DSA! 💪 Under the Guidance of : Rudra Sravan kumar and Manoj Kumar Reddy Parlapalli #Day56 #Python #LeetCode #DSA #BinarySearch #Algorithms #CodingJourney #100DaysOfCode #10000Coders 🚀
To view or add a comment, sign in
-
-
🚀 Day 16 Task – Python Mini Challenge Today’s task was a simple yet powerful exercise to strengthen my looping and conditional logic skills. 🔹 Task: Given a list of numbers, calculate the sum of even and odd numbers separately. 🔹 What I implemented: ✔️ Method 1: Stored even & odd numbers in separate lists and used sum() ✔️ Method 2: Calculated sums directly using variables (more optimized approach) 🔹 Key takeaway: There’s always more than one way to solve a problem. Writing multiple approaches helps in understanding efficiency and clean coding practices. 🔹 What I learned deeply: Using loops effectively Applying conditional logic (if-else) Writing optimized solutions instead of relying only on extra space github link : https://lnkd.in/g4iZcnGt 📌 Completed the task and tested it with different inputs successfully. Building consistency, one problem at a time 💪🚀 #Python #100DaysOfCode #Coding #ProblemSolving #DeveloperJourney #LearnInPublic Codegnan BhanuTeja Garikapati
To view or add a comment, sign in
-
More from this author
Explore related topics
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