🚀 DSA Practice – Check if a String is a Palindrome Today I worked on a fundamental string challenge: Determining whether a given string is a palindrome. 📌 Problem Statement: Given a string s, verify if it reads the same backward as forward. A palindrome is a sequence that is identical even when its order is reversed. 🧠 My Approach: 1️⃣ Clean the Data: Convert the string to a uniform case (lowercase) to ensure the comparison is case-insensitive. 2️⃣ Reverse and Compare: Use Python’s powerful slicing technique s[::-1] to create a reversed version of the string. 3️⃣ Verification: Compare the original string with the reversed one. If they match, it's a palindrome; otherwise, it's not. ⚙️ Example: Input: "madam" → Output: True Input: "hello" → Output: False 📊 Complexity: Time Complexity: $O(n)$ (where $n$ is the length of the string, as we traverse it to reverse). Auxiliary Space: $O(n)$ (to store the reversed version of the string). 💻 Language Used: Python This problem is a great way to practice string slicing and understanding how data is stored and compared in memory. It's a stepping stone toward more complex "Two-Pointer" string problems! #DSA #Python #CodingPractice #ProblemSolving #Strings #Palindrome #LearningInPublic
Python Palindrome Checker: String Slicing and Comparison
More Relevant Posts
-
INSTEAD OF WASTING TIME AND TRYING TO GET FIGURES. WHY NOT USING CODE?? Sometimes, lecturers or organizations need to generate different sets of questions for multiple candidates, especially when working with matrices. However, this often requires a lot of manual effort and can be time-consuming. Why not simplify the process using NumPy in Python? With just a few lines of code, you can easily generate multiple variations of matrix-based questions efficiently and save valuable time. #randint is an inbuilt function of the random module of numpy #Syntax: np.random.randint(start, stop (rows, columns)) a=np.random.randint(2,30, (3,3)) b=np.random.randint(2,30, (3,3)) c=np.random.randint(2,30, (3,3)) d=np.random.randint(2,30, (3,3)) e=np.random.randint(2,30, (3,3)) #DataScience #Python #NumPy #Education #Automation
To view or add a comment, sign in
-
-
Last week I shared results from an ABRF-LMRG study suggesting a large increase in inter-analyst variability when comparing Imaris/Arivis/Aivia workflows to Python/ImageJ/CellProfiler workflows. I also started a discussion on Image.sc to explore possible causes. It turns out a major contributor to the apparent variability was small mistakes in the code used to generate the plots. The original plot from the paper is on the left, with a corrected plot on the right. Comparing image analysis outputs is inherently challenging—differences in conventions like x/y ordering, units (microns vs. pixels), and even simple naming inconsistencies can introduce errors. The authors had intended to correct for these issues, but some datasets were not adjusted for x–y mix-ups and pixel-to-micron conversions. After fixing these issues in the code, the results change substantially: the Imaris/Arivis/Aivia and Python/ImageJ/CellProfiler solutions are much closer, and the previously observed order-of-magnitude differences (on a log scale) are no longer present. There may still be a real signal—Python/ImageJ/CellProfiler results appear slightly more variable, spanning both the best and worst scores—but the very large errors initially observed are no longer present in the plot.
To view or add a comment, sign in
-
-
Methods vs Functions - I Finally Get The Difference! I used to think methods and functions were the same. Today I learned they're NOT! 🤯 The difference: Function = Standalone tool 🔧 len("Python") # Function - works on its own print("Hello") # Function - independent Method = Tool attached to an object 🎒 "Python".upper() # Method - belongs to the string [1, 2, 3].append(4) # Method - belongs to the list The pattern I noticed: ✅ Function: function_name(object) ✅ Method: object.method_name() Real example: # Function approach: text = "python" result = len(text) # len() is a function # Method approach: text = "python" result = text.upper() # .upper() is a method What I learned: Methods = Actions that objects can DO to themselves! • Strings can .upper() themselves • Lists can .append() to themselves • Numbers can't do much (they're just values) Think of it like this: • Function = You wash the car (external action) • Method = Car washes itself (built-in action) My simple rule now: See a dot (.) before the action? → It's a method! No dot? → It's a function! Did you know this difference? Or were you using them thinking they're the same? 💭 #Python #Methods #Functions #PythonBasics #LearnPython #ProgrammingConcepts #CodingFundamentals
To view or add a comment, sign in
-
-
Day 3 of #50DaysDSA Problem Solved: Reverse Vowels of a String Today’s problem focused on efficient string manipulation using the two-pointer technique, a fundamental approach in algorithm design. Problem Statement: Given a string, reverse only the vowels while keeping all other characters in their original positions. Approach: Used two pointers (start and end) to traverse the string Identified vowels using a set for constant-time lookup Swapped vowels in-place while skipping non-vowel characters Continued until both pointers met Complexity Analysis: Time Complexity: O(n) Space Complexity: O(n) (due to string-to-list conversion in Python) Key Takeaway: This problem reinforces how a well-applied two-pointer strategy can lead to clean and optimal solutions without unnecessary data structures. #DSA #DataStructures #Algorithms #Python #SoftwareDevelopment #CodingPractice #Leetcode75 LeetCode Dhanraj Sahu
To view or add a comment, sign in
-
-
🚀 Solved: Find a String (Substring Count) Challenge Just solved another problem on HackerRank under the Python Strings section! ✅ 🧠 Problem Overview: Count how many times a substring appears in a string — including overlapping occurrences. 🔍 Key Learnings: Practiced string traversal techniques Understood why built-in methods like count() may not always work (no overlapping support) Strengthened concepts of slicing and iteration in Python 💡 Example Insight: For string "ABCDCDC" and substring "CDC", the answer is 2 (overlapping counts matter!). ⚡ Approach Used: Iterated through the string Compared substrings using slicing Counted valid matches efficiently 📈 Problems like this help build strong fundamentals in string manipulation, which is crucial for coding interviews and real-world applications. #Python #HackerRank #Coding #Strings #ProblemSolving #DSA #LearningJourney #AI link of #Solution :- https://lnkd.in/gtqcy8fX
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
-
-
📊 Comparing Two Outlier Removal Approaches in Python When cleaning datasets, how you remove outliers matters more than you think. I recently compared two common strategies: 1️⃣ Column-wise removal – Drop outliers sequentially, one column at a time. 2️⃣ Dataset-level removal – Flag all outliers across the entire dataset first, then remove them together. 🔍 What I found: The column-wise approach changes the IQR bounds after each removal, causing many non‑outlier rows to be wrongly filtered out (545 → 365 rows). The dataset-level approach respects original distributions, removes only true outliers (545 → 463 rows), and avoids over‑cleaning. ✅ Takeaway: Always identify outliers globally before removing them – your data will thank you. 📁 Used Python, pandas, IQR method, and a housing dataset. 🔗 Full code & notebook: https://lnkd.in/gheGYYEz #DataScience #Python #OutlierDetection #DataCleaning #Pandas #MachineLearning
To view or add a comment, sign in
-
Sixth PR in skrub, and the most interesting part of it wasn't the PR itself. PR: https://lnkd.in/eGyiGfcq While updating gallery examples to load datasets from file paths, I found that fetch_employee_salaries(split="test").employee_salaries_path was returning an empty CSV. Not something you'd catch by reading the code. Only came up because I was actually running the examples. Flagged it, maintainers confirmed. The path fix itself was routine, part of a broader effort (#1934) to standardize dataset loading across the example suite. One file I intentionally left untouched since it depended on fetch_figshare, which no longer exists. #opensource #python #skrub #scikitlearn #documentation
To view or add a comment, sign in
-
-
#Gemma 4 dropped yesterday -- four open models from 2B to 27B, running locally via Ollama with native function calling -- a great step forward for local model development. But if you've built pipelines on local models before, you know "supports function calling" and "returns valid output every time" aren't the same thing Paul Schweigert wrote a walkthrough on structured outputs with Gemma 4, pairing it with #Mellea -- an open-source Python library where Instruct-Validate-Repair is a key pattern. Declare a typed function, attach validation requirements, and automatically repair on failure 👓 Worth a read if you're building on Gemma 4: https://lnkd.in/eDXjmZV4 🍄 Mellea: https://mellea.ai/
To view or add a comment, sign in
-
Well, things were busy for a bit, but I did have some downtime the past couple of weeks (gotta burn that leftover leave at the end of the FY)... So, I finally got around to finishing off that statistical library I was playing with building last summer. Maybe someone will find it interesting. https://lnkd.in/gpbqxfE4 Oh, and P Travis Jardine - I even made a Python binding layer just for you! (curious to know if it is at all useful, so please do play around with it) https://lnkd.in/ePMjA8DU
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
Nice approach! Python slicing makes the solution very clean and readable. Another interesting variation is solving it using the two-pointer technique, which can reduce the auxiliary space to O(1). Great practice problem for strengthening string fundamentals.