⭐ Day 19 #50daysofcode : Solved the Zigzag Conversion problem! ⭐ Today's challenge was about converting a string into a zigzag pattern across a specified number of rows and then reading the pattern line by line. ✅Problem Breakdown: Given a string and a number of rows, the task was to arrange the string in a zigzag pattern. The characters are placed in rows, and the direction alternates between going down and up as we traverse across the rows. ✅Approach: 1. If the number of rows is 1, there's no zigzag, so the string remains unchanged. 2 . I used an array to represent the rows and iterated through the string, placing each character in the correct row while alternating the direction when hitting the top or bottom row. 3.Finally, I joined all the rows to form the final result. ✅Time Complexity: The time complexity of the solution is O(n), where n is the length of the string, as the algorithm only makes one pass through the string. #100DaysOfCode #LeetCode #ZigzagConversion #Python #Algorithms #DataStructures #CodingChallenges #ProblemSolving #google
Ishan Bauri’s Post
More Relevant Posts
-
[Day 23] Leetcode3163: Compressed String Algorithm 🔹 Problem: Given a string word, compress it by iteratively removing a maximum-length prefix of repeating characters (up to 9 times) and appending the count followed by the character to the result. 🔹 Approach: Used a while-loop to iterate through the characters in word, counting consecutive characters up to 9 or until a different character appears. Stored results in a list to minimize memory usage, then joined at the end. 🔹 Language: Python 💡 Solution accepted with a runtime of 338 ms, beating 41.67% of other submissions! 🎉 Memory usage was 16.27 MB, beating 79.17% of other submissions, achieving a balance between time and space efficiency. 💪 Another milestone in the 100 Days of Code journey! Excited to learn more and improve further with new challenges each day. 🔖 Every small step counts! Onward to Day 24! #DrGViswanathan #Challenge #100DaysOfCode #Day23Completed #CodingJourney #CompressedStringAlgorithm #Python #Algorithms #ProblemSolving #AIandML #LearningEveryday #Optimization #Motivation #DailyChallenge
To view or add a comment, sign in
-
-
🚀 LeetCode Day 41: Intersection of Two Arrays🚀 👩💻 Here’s how I approached it: To tackle this, I thought about leveraging Python's set for its efficient O(1) lookups. My solution involved: 1️⃣ Converting both arrays into sets to make element checks faster. 2️⃣ Iterating through the smaller array to minimize unnecessary comparisons. 3️⃣ Using a conditional to identify the intersecting elements and store them in a set. 📊 Complexity analysis: Time complexity: O(m+n)O(m + n)O(m+n), where mmm and nnn are the sizes of the two arrays. Space complexity: O(m+n)O(m + n)O(m+n) because I created sets for both arrays. 💬 What about you? How would you solve this problem? Do you have a go-to approach for finding intersections or optimizing such tasks? Let’s exchange ideas and grow together! 🚀 #CodingJourney #ProgrammingChallenges #Algorithms #DataStructures #Python #ContinuousLearning
To view or add a comment, sign in
-
-
🚀 Day 3 of #100DaysOfCode Challenge! Today, I tackled the "Reverse String" problem on LeetCode, continuing my journey through string manipulation and algorithm optimization. 🔍 Problem Overview: Given a string as an array of characters, reverse it in place with O(1) extra memory. 🧠 Approach: 🔹 Two-Pointer Technique: Initialized pointers at the start and end of the array. Swapped characters while moving the pointers towards the center. Continued until the entire string was reversed. 📊 Results: 🔹 Runtime: 38 ms (Faster than 95% of Python submissions) 🔹 Memory: Efficient usage with in-place modification. 💡 Key Takeaways: 🔹 String Manipulation: Reinforced the importance of in-place operations for memory efficiency. 🔹 Algorithmic Thinking: Developing a deeper understanding of pointers and their role in optimizing algorithms. 🤝 Special Thanks To: Everyone supporting me on this coding journey! Here's to more challenges and growth. Muhammad Hateem Hussain, Muhammad Hanzla, Asad Ali, Naveed Ahmed #Python #LeetCode #Algorithms #CodingChallenge #100DaysOfCode
To view or add a comment, sign in
-
-
Day 22 of 100 Days of Code!** 🌟 Today, I worked on the **"Add Binary"** problem on LeetCode. The challenge was to add two binary strings and return their sum as a binary string. It’s a classic problem that helped me dive deeper into string manipulation, binary arithmetic, and algorithm optimization. ### Key Learnings: - Handling different string lengths by padding zeros. - Efficiently iterating from the least significant to the most significant bit. - Carrying over any excess sum to the next bit, just like in decimal addition. I achieved a runtime of **33 ms**, beating **81.52%** of submissions! 🎉 Memory usage was **16.75 MB**, and I’m continuously working on optimizing it. 🚀 Every challenge is helping me sharpen my problem-solving and coding efficiency. I’m excited to continue improving with each day! **Onward to Day 23!** #100DaysOfCode #LeetCode #BinaryAddition #Python #ProblemSolving #CodingJourney #ContinuousLearning
To view or add a comment, sign in
-
-
🚀 Day of 84 LeetCode 100-Day Challenge Today, I solved Problem 34: Find First and Last Position of Element in Sorted Array! 🔍 Problem Overview: Given a sorted array, the challenge was to find the starting and ending indices of a target value. If the target wasn’t present, I had to return [-1, -1]. 💡 Key Focus: The problem required achieving O(log n) runtime complexity, so an efficient algorithm like binary search is essential! However, here's my initial approach using a loop for clarity: class Solution(object): def searchRange(self, nums, target): if not nums: return [-1, -1] l = [] for i in range(len(nums)): if nums[i] == target: l.append(i) if len(l) == 2: break if not l: return [-1, -1] if len(l) == 1: l.append(l[0]) if len(l) == 2: for i in range(len(nums) - 1, -1, -1): if nums[i] == target: l[1] = i break return l ✅ Output Examples: Input: [5,7,7,8,8,10], Target: 8 → Output: [3, 4] Input: [5,7,7,8,8,10], Target: 6 → Output: [-1, -1,-1] Approach: You need to find the first and last positions of a target value in a sorted array by traversing the array. If the target value isn’t found, return [-1, -1]. The solution must run in O(log n) time complexity. #LeetCode #ProblemSolving #Python #CodingJourney #100dayschallenge
To view or add a comment, sign in
-
-
🚀 Day 11 of #100DaysOfPython 🚀 Today's challenge was all about solving a classic problem: Finding the Longest Common Prefix in an array of strings. ✨ The Problem: Given an array of strings, find the longest common prefix. If there’s none, return an empty string. 🧩 Examples: Input: ["flower", "flow", "flight"] Output: "fl" Input: ["dog", "racecar", "car"] Output: "" (No common prefix here!) 💡 What I Learned: String manipulation is an art! Handling edge cases like empty arrays or no shared prefixes can make or break your solution. Writing clean, efficient code for a problem like this requires clarity in thought and logic. This challenge was a great way to build problem-solving skills while diving deeper into Python. Every small step in this journey brings so much excitement! 🎉 What do you think? How would you approach this problem? Drop your thoughts below! ⬇️ #Python #CodingJourney #100DaysChallenge #ProblemSolving #LongestCommonPrefix #Day11hashtag #PythonProgramming #100DaysOfPython #CodeNewbie #CodingChallenges #TechCommunity #ProblemSolving #DeveloperJourney
To view or add a comment, sign in
-
-
🌟 Day 7: One Week of Progress! 🚀 Another day, another step forward in my LeetCode 75 Day Challenge! Today’s problem was both interesting and challenging, focusing on efficient array manipulation without extra space. Here’s what I tackled: 🧩 Problem: Product of Array Except Self Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. Example 1: Input: nums = [1,2,3,4] Output: [24,12,8,6] Example 2: Input: nums = [-1,1,0,-3,3] Output: [0,0,9,0,0] 💻 Solution: GitHub Repository - https://lnkd.in/gVxkXpNH LeetCode : https://lnkd.in/gAkMB-CP #LeetCode75 #CodingChallenge #Python #Algorithms #DataStructures #LearningJourney #ProblemSolving
To view or add a comment, sign in
-
Day 83 of #100DaysOfCode The peek() operation in a stack allows you to view the top element of the stack without removing it. This can be useful when you need to see the current top element but don’t want to modify the stack. Below is an example of how you can implement and use the peek() operation in a stack. In this example: 1. We define a Stack class with push, pop, peek, and isEmpty methods. 2. We create an instance of Stack and push elements onto it. 3. The peek() method returns the top element (4) without removing it from the stack. 4. The state of the stack remains unchanged after calling peek(). #100DaysOfCode #pythonprogramming #datastructuresandalgorithms #arrays #100DaysOfCodingChallenge #CodingJourney #codinggirls #girlswhocode #WomenInTech #datastructures #python
To view or add a comment, sign in
-
-
[Day 6] Leetcode58: Length of Last Word 🔹 Problem: Given a string, return the length of the last word. A word is defined as a sequence of non-space characters. 🔹 Approach: I used the strip() method to remove leading and trailing spaces, followed by split() to separate words. The last word’s length is then returned. If the string is empty, it returns 0. 🔹 Language: Python 💡 My solution was accepted with a runtime of 14 ms, beating 52.84% of other submissions! 🎉 The memory usage was 11.62 MB, which beats 92.37% of other submissions, a pretty good balance between time and space efficiency. 💪 Another milestone in my 100 Days of Code journey! Excited to learn more and improve further as I tackle new challenges each day. 🔖 Every small step counts! Onward to Day 7! #DrGViswanathan #Challenge #100DaysOfCode #Day6Completed #CodingJourney #LengthOfLastWord #Python #Algorithms #ProblemSolving #AIandML #LearningEveryday #Optimization #Motivation #DailyChallenge
To view or add a comment, sign in
-
-
[Day 3] Leetcode962: Maximum Width Ramp 🔹 Problem: Given an array of integers, find the maximum width ramp, where the ramp's left number is smaller than or equal to the right number. 🔹 Approach: I implemented a two-pass algorithm, leveraging a stack to track potential ramp start indices and then traversed the array in reverse to calculate the maximum ramp width efficiently. By iterating from both ends, I minimized unnecessary comparisons and achieved better performance. 🔹 Language: Python My solution was accepted with a runtime of 378 ms (beating 50% of submissions) and memory usage of 18.10 MB. 🎉 I'm thrilled to see my progress but always eager to optimize further! 🚀 💪 Day 3 of my 100 Days of Code journey is complete, and I'm excited to continue solving more problems and improving my skills. 🔖 Every small step counts! Onward to Day 4! 💻 #DrGViswanathan #Challenge #100DaysOfCode #Day3Completed #CodingJourney #Python #Algorithms #ProblemSolving #AIandML #LearningEveryday #Optimization #Motivation #DailyChallenge
To view or add a comment, sign in
-