Day 5 of #14DaysOfPython Completed Strings (core + advanced) and consolidated everything in one place. Strings are a major part of problem solving — most questions are based on text manipulation. Concepts Covered: Indexing and slicing Traversing using loops (for, while) Built-in methods: lower(), upper(), strip(), replace() ASCII basics using ord() and chr() String immutability Concatenation and repetition Membership operators (in, not in) String comparison Advanced methods: split(), join(), find(), count() String formatting (f-strings) Escape characters Validation methods: isalpha(), isdigit(), isalnum() Problems practiced: Palindrome check Reverse a string Count vowels and consonants Remove spaces Anagram check Character frequency Remove duplicate characters First non-repeating character Key takeaway: Most string problems follow the same pattern — iterate through characters, apply conditions, and keep track of counts. Understanding this pattern makes complex problems easier to solve. Strings topic completed. Moving to next. #HackerRank #Python #ProblemSolving #CodingJourney #Developer #LearningInPublic #codegnan
Python Strings: Indexing, Methods, and Problem Solving
More Relevant Posts
-
🚀 Day 75 of #100DaysOfCode 🔥 LeetCode 179 – Largest Number 💡 Problem: Given a list of non-negative integers, arrange them such that they form the largest possible number. 🧠 Key Insight: Normal sorting won't work here ❌ We need a custom comparator based on string concatenation. 👉 Compare: - ""a + b"" vs ""b + a"" - Whichever gives a larger value should come first. ⚙️ Approach: 1. Convert numbers to strings 2. Sort using custom comparison logic 3. Join the result 4. Handle edge case (like "[0,0] → "0"") ⚡ Complexity: - Time: O(n log n) - Space: O(n) 🎯 Result: ✅ Accepted ⚡ Runtime: 0 ms (100%) 📌 Lesson Learned: Sometimes sorting logic depends on combination, not value. #LeetCode #Python #CodingJourney #DSA #100DaysOfCode #Sorting #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Solved a great problem today: “Consecutive 1’s Not Allowed” At first glance, it looked like a simple binary string problem… but it quickly turned into a lesson in pattern recognition and dynamic thinking. 📌 What the problem was about: Count all binary strings of length n such that no two 1’s are consecutive. 💡 What I learned: Instead of brute forcing all combinations (which would be exponential), the key was to observe a pattern: If a string ends with 0 → we can add 0 or 1 If it ends with 1 → we can only add 0 This leads to a recurrence: 👉 dp[n] = dp[n-1] + dp[n-2] Which is basically the Fibonacci pattern in disguise. 🧠 Big takeaway: Many problems are not about coding harder… they’re about seeing the hidden pattern behind the problem. This was a reminder that: Brute force is rarely the answer Thinking in terms of state transitions is powerful Optimization often comes from observation, not syntax 📷 Sharing my solution screenshot below 👇 #DataStructures #DynamicProgramming #ProblemSolving #Python #LearningInPublic #DataAnalyticsJourney
To view or add a comment, sign in
-
-
Just solved “First Matching Character From Both Ends” 🚀 💡 My approach (simple & efficient): Instead of overcomplicating it, I used a two-pointer mindset without explicitly creating two pointers. Loop through the string from the start For each index i, compare: s[i] (from the front) s[n - i - 1] (from the back) The moment both match → return the index If no match → return -1 ✨ This works because we're checking symmetry from both ends in a single pass (O(n)) with O(1) space. Sometimes the best solutions aren’t fancy — they’re just clean and intuitive. 🔥 Consistency > Complexity. Small wins like this build strong problem-solving instincts. #LeetCode #DSA #Python #CodingJourney #ProblemSolving #TechGrowth #CodeDaily #WomenInTech #FutureEngineer #100DaysOfCode #KeepBuilding
To view or add a comment, sign in
-
-
My thesis was stuck. A matrix had the wrong shape and I had no idea why. I could have printed the entire dataset to find the error. I did not. Instead I used Python's debugger. One breakpoint. One look at the intermediate state. Wrong dimensions. Found in seconds. That moment changed how I work. Not because debugging saved my thesis. But because it taught me something I still use every day: You do not need to see all the data to understand what is wrong. You just need to see the right data at the right moment. Since then, every time a pipeline breaks or a model behaves unexpectedly, I reach for the debugger first. Not print statements. Not guesswork. A breakpoint. An intermediate result. A clear answer. Debugging is not a last resort. It is the fastest way to understand what your code is actually doing. What is your go-to strategy when something breaks unexpectedly? #Python #Debugging #DataScience #MachineLearning #FreelanceDataScientist
To view or add a comment, sign in
-
-
Most FastAPI codebases look clean at first glance. Until you try to change something. I’ve noticed a pattern — a lot of complexity doesn’t come from the problem itself, but from where the logic lives. When routes start handling more than just request/response, things get harder to reason about. Lately, I’ve been keeping one constraint: Routes should stay thin. They handle the HTTP layer. All business logic moves to services. It’s a small shift, but it changes a lot: 1) Clearer separation of concerns 2) Easier testing 3) Fewer side effects when making changes Also started appreciating dependency injection more. Not as a framework feature, but as a way to keep things decoupled and predictable. Nothing groundbreaking here. But in a time where a lot of code is being generated faster than it’s being designed, maintainability comes down to how consistently we apply these basics — not whether we know them. Curious how others approach structuring FastAPI projects at scale. #FastAPI #BackendDevelopment #CleanCode #SoftwareEngineering #Python
To view or add a comment, sign in
-
Just solved “Second Largest Digit in a String” on LeetCode — and here’s the simple approach I followed 👇 Instead of overcomplicating it, I focused on clean thinking + Python basics: 🔹 Converted the string into a set → removes duplicates instantly 🔹 Filtered only digits using isdigit() 🔹 Stored them as integers in a list 🔹 Sorted the list → easy access to largest & second largest 🔹 Edge case check: if less than 2 digits → return -1 💡 Key takeaway: Sometimes the most optimal solution isn’t about complex algorithms — it’s about using the right built-in tools smartly. 🚀 What I’m improving with each problem: • Writing cleaner logic • Thinking in steps instead of rushing • Handling edge cases early Consistency > Complexity. #LeetCode #DSA #Python #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
📝 Why I deliberately write "boring" code: Fancy code is impressive. Boring code is reliable. What boring code looks like: ✅ Clear variable names (customer_count not cc) ✅ Small functions that do one thing ✅ Comments that explain WHY, not WHAT ✅ Consistent formatting ✅ Error handling for edge cases Who benefits? → Future me (6 months from now, I won't remember) → My teammates (they can actually read it) → Production (less surprises at 2 AM) Clever code makes you feel smart. Boring code makes you effective. Which do you prefer to maintain? #CodeQuality #Python #DataEngineering #CleanCode
To view or add a comment, sign in
-
Today I worked on a classic string manipulation problem that looks simple but tests your understanding of logic and edge cases. 🔍 Problem: Given a string and a substring, count how many times the substring appears in the main string. ⚠️ The catch? 👉 You must count overlapping occurrences as well. 💡 Approach I Used: Instead of using built-in shortcuts, I applied a sliding window technique: ++Loop through the string ++Extract a substring of the same length ++Compare it with the target substring ++Increment count when matched This ensures we don’t miss overlapping patterns. 🧠 Key Learning: Sometimes, simple problems reveal powerful concepts. This one reinforces: ++String slicing ++Loop boundaries ++Sliding window logic 📌 Example: "ABCDCDC" → "CDC" appears 2 times (including overlap) 💻 Check out the visuals: 🖼️ Problem breakdown 🧑💻 Python solution 🔥 Why this matters? This pattern is widely used in: --Text processing --Pattern matching --Data parsing #Python #HackerRank #CodingPractice #DataStructures #ProblemSolving #100DaysOfCode #LearningInPublic #SoftwareEngineering
To view or add a comment, sign in
-
-
📌 Problem: 1679. Max Number of K-Sum Pairs 💡 Approach: First, sort the array to efficiently apply the two-pointer technique. Initialize two pointers: one at the start (left) and one at the end (right). If the sum equals k, we found a valid pair → increment count and move both pointers If the sum is greater than k, move the right pointer to reduce the sum If the sum is smaller than k, move the left pointer to increase the sum Continue until both pointers meet. ⚙️ Key Insight: Sorting enables efficient pair finding Two-pointer approach avoids checking all pairs (O(n²)) Greedy selection ensures maximum number of operations ⏱️ Time Complexity: O(n log n) (due to sorting) 📦 Space Complexity: O(1) (ignoring sorting space) 📚 What I learned: Two-pointer technique on sorted arrays Optimizing pair problems from brute force to efficient solutions #LeetCode #DSA #Algorithms #Coding #ProblemSolving #Python #TwoPointers #Greedy #InterviewPreparation #CodingJourney
To view or add a comment, sign in
-
🚀 Day 96 of #LeetCode Journey 📌 Problem: Count and Say (Medium) Today’s problem looked simple at first glance—but it quickly tested my ability to observe patterns and think recursively. 🔍 Key Idea: The sequence builds itself by describing the previous term: - Start with "1" - Then keep "reading" the digits of the last result Example progression: 1 → "1" 2 → "11" (one 1) 3 → "21" (two 1s) 4 → "1211" (one 2, one 1) 💡 What I learned: - This problem is all about pattern recognition + string manipulation - It’s essentially run-length encoding (RLE) - Breaking the problem into a helper logic made it much cleaner ⚡ Challenges faced: - Handling consecutive characters correctly - Avoiding off-by-one mistakes while traversing - Keeping the logic readable instead of overcomplicating 📈 Outcome: ✅ Accepted ⚡ Runtime: 7 ms Consistency > Motivation. Showing up every day. #Day96 #LeetCode #DSA #ProblemSolving #CodingJourney #Python #Consistency
To view or add a comment, sign in
-
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