🚀 Day 78 of #100DaysOfCode — Reverse Integer Challenge Hey everyone! 👋 Today's challenge is a classic: "Reverse Integer" — a problem that tests your understanding of integer manipulation, overflow handling, and edge cases with negative numbers. We need to reverse the digits of a signed 32-bit integer, but catch the overflow if the reversed number goes beyond the 32-bit range. 👨💻 What l practiced today: ✅ Digit Extraction: Using modulo and division to peel off digits. ✅ Integer Reversal: Building the reversed number step by step. ✅ Overflow Prevention: Checking boundaries before the number exceeds 32-bit limits. ✅ Sign Handling: Properly managing negative integers. 📌 Today’s Task: ✔ Given a signed 32-bit integer x. ✔ Return x with its digits reversed. ✔ If reversing causes overflow (outside [−231,231−1] [−231 ,231 −1]), return 0. ✔ You cannot use 64-bit integers for storage. Examples: Input: x = 123 → Output: 321 Input: x = -123 → Output: -321 Input: x = 120 → Output: 21 🧠 Key Insight: Reverse digits using while x != 0, but check for overflow before multiplying the reversed result by 10. Use INT_MAX and INT_MIN equivalents (or 2**31 - 1 and -2**31 in Python) to validate. 🔗 Hashtags: #100DaysOfCode #Day78 #Python #LeetCode #DSA #IntegerManipulation #OverflowHandling #MathInCode #AlgorithmPractice #LogicBuilding
Pradumya Gupta’s Post
More Relevant Posts
-
HoloViz MCP now ships a CLI. The same tools that power AI assistants through the Model Context Protocol — semantic documentation search, component introspection, best-practice skills — are now available directly in your terminal. The namespaces mirror Python imports: `pn`, `hv`, `hvplot`. If you know `import panel as pn`, you already know the CLI. Every command supports three output formats: - `--output pretty` — Rich tables for terminal use (default) - `--output markdown` — for piping into LLMs or documentation - `--output json` — for scripting and automation $ pip install holoviz-mcp
To view or add a comment, sign in
-
-
❄️ takeUforward — Day 38 ✅ A Number After a Double Reversal | Number Manipulation | LeetCode Today I worked on a number manipulation problem involving reversing digits twice and checking if the result equals the original number. 💡 Problem Statement Given an integer "num", reverse the number twice and check whether the final value is equal to the original number. 🧠 Approach • Store the original number. • Reverse the number using modulo ("% 10") and division ("// 10"). • Reverse the result again. • Compare the final value with the original number. 🐍 Python Code class Solution: def isSameAfterReversals(self, num: int) -> bool: orginal = num sum_ = 0 sum2 = 0 while num > 0: last_digit = num % 10 sum_ = (sum_ * 10) + last_digit num //= 10 while sum_ > 0: lsd = sum_ % 10 sum2 = (sum2 * 10) + lsd sum_ //= 10 return True if sum2 == orginal else False ⏱ Complexity • Time: O(d) — where d is number of digits • Space: O(1) 📌 Key Learning Reversing numbers using digit extraction helps build strong fundamentals in number-based algorithms and edge case handling. 🚀 Day 38 completed — improving number manipulation skills step by step. #Python #DSA #LeetCode #ProblemSolving #CodingJourney #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 9/30 | LeetCode Problem: Binary Search (704) Problem: Given a sorted array of integers nums and a target, return the index if the target exists. If not, return -1. 🧠 Approach: Binary Search Since the array is already sorted, we can apply Binary Search: Use two pointers: l (left) and r (right) Find the middle element Compare target with nums[mid] Reduce the search space by half each time This makes the solution very efficient. ⏱️ Complexity Time: O(log n) Space: O(1) 🧾 Python Code class Solution(object): def search(self, nums, target): l = 0 r = len(nums) - 1 while l <= r: mid = (l + r) // 2 if target == nums[mid]: return mid elif target < nums[mid]: r = mid - 1 else: l = mid + 1 return -1 ✅ Result Accepted ✅ Runtime: 0 ms (Beats 100%) Memory efficient 🎯 Key Learning Binary Search is a foundational algorithm used in: Search problems Optimization problems Interview questions Mastering it is essential for every developer. 🔖 Hashtags #LeetCode #30DaysOfLeetCode #Day9 #BinarySearch #Python #DSA #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
𝗦𝗶𝗺𝗽𝗹𝗲 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 𝗳𝗼𝗿 𝗢𝘂𝘁𝗹𝗶𝗲𝗿 𝗗𝗲𝘁𝗲𝗰𝘁𝗶𝗼𝗻: 𝗭-𝘀𝗰𝗼𝗿𝗲 𝘃𝘀 𝗜𝗤𝗥 Are you using the ±3σ rule to detect outliers? It works well, but there are some important considerations. Let’s break down some common methods. 1️⃣ Z-score Method / ±3σ rule The 3 sigma rule measures how far a value is from the mean in units of standard deviation: Z = (x−μ)/σ If |Z| > 3 → potential outlier. ✅ Works well when data is approximately normally distributed. If the data is skewed, it can affect the results. 2️⃣ IQR Method / Boxplot Rule The IQR method is based on quartiles: - Q1 (25th percentile) - Q3 (75th percentile) - IQR = Q3 − Q1. Outlier rule: x < Q1−1.5⋅IQR x > Q3+1.5⋅IQR ✅ It is more robust to skewness because it uses medians and percentiles instead of the mean. #DataScience #Statistics #Python #MachineLearning #OutlierDetection #DataAnalysis #Research
To view or add a comment, sign in
-
-
Day 7 of #200DaysOfCode! 🚀 One week down! Today, I took a break from complex data structures to parse some ancient history: "Roman to Integer" (LeetCode 13). 🏛️ At first glance, this seems like simple addition. You just sum up the symbols, right? III = 1 + 1 + 1 = 3 XV = 10 + 5 = 15 But the "Subtraction Rule" throws a wrench in the works. If a smaller symbol appears before a larger one (like IV or IX), it subtracts instead of adds. The Logic (The Lookahead Technique): Instead of complicated string parsing or multiple passes, I used a clean linear scan with a simple rule: Map the Values: I used a Python Dictionary (Hash Map) to store the values ('I': 1, 'V': 5, etc.) for instant lookups. Iterate & Compare: I looped through the string and simply peeked at the next character. * If Current < Next: It means we are in a subtraction case (like the I in IV). I subtract the current value from the total. Otherwise: I simply add the current value. Example: For MCMXCIV (1994): C (100) < M (1000) → Subtract 100 X (10) < C (100) → Subtract 10 I (1) < V (5) → Subtract 1 This logic handles every edge case in a single pass O(N). The result was a flawless 0 ms runtime, beating 100.00% of Python submissions! 7 days in, and the streak is strong. 🧱 Have you tried the reverse problem (Integer to Roman)? I hear the logic is quite different! 👇 #200DaysOfCode #Python #LeetCode #Algorithms #HashMap #Logic #ProblemSolving #CodingChallenge #DeveloperJourney
To view or add a comment, sign in
-
-
Previously on accessing data, I focused on various functions which are used like .iloc[], .type, .unique(), .describe(), .head(), etc. Today, I focus on .loc[], which is similar to .iloc[]. The major difference between both being that .loc[] uses labels to determine the positions of values unlike .iloc[] which uses integers. In this session, I explored how to use pandas .loc[] for: • Selecting rows and columns using labels • Slicing specific column ranges • Applying conditional filtering • Replacing values based on conditions From extracting structured subsets of data to modifying values dynamically, mastering .loc[] improves both efficiency and clarity in real-world datasets. #DataAnalysis #Python #Pandas #DataAnalytics #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 8/30 | LeetCode Problem: Sort Colors (75) Problem: Given an array nums containing only 0s, 1s, and 2s, sort the array in-place so that colors are ordered as: 🔴 0 → ⚪ 1 → 🔵 2 Without using the built-in sort function. 🧠 Approach: Dutch National Flag Algorithm We use three pointers: a → position for 0 (left) b → position for 2 (right) c → current index Logic: If nums[c] == 0 → swap with a, move both forward If nums[c] == 2 → swap with b, move b backward If nums[c] == 1 → just move c This sorts the array in one pass. ⏱️ Complexity Time: O(n) Space: O(1) (in-place) 🧾 Python Code class Solution: def sortColors(self, nums): a = 0 # left pointer (0s) b = len(nums) - 1 # right pointer (2s) c = 0 # current index while c <= b: if nums[c] == 0: nums[a], nums[c] = nums[c], nums[a] a += 1 c += 1 elif nums[c] == 2: nums[b], nums[c] = nums[c], nums[b] b -= 1 else: c += 1 ✅ Result Accepted ✅ Runtime: 0 ms (Beats 100%) In-place & optimal solution 🎯 Takeaway Understanding pointer-based algorithms helps solve array problems efficiently without extra space . 🔖 Hashtags #LeetCode #30DaysOfLeetCode #Day8 #Python #Arrays #TwoPointers #DSA #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
Handling outliers has always been a challenge for ML practitioners. From basic statistical methods to modern machine learning approaches, there are many techniques available for detecting and handling outliers. The difficult part is figuring out which method actually works best for your data. To make this easier, I built a Python library called AnLOF that helps handle outliers more effectively. Check it out: PyPI: https://lnkd.in/gCpfPgfs github : https://lnkd.in/gCnQN4Eu I'd love to hear your feedback
To view or add a comment, sign in
-
Regex Insight: Email Validation While revisiting regular expressions, this small pattern is a great illustration of how character classes and quantifiers work together: The code: [\w._%+-]+@ [] → defines a character class (match one character from the set) \w → letters, digits, underscore . % + - → commonly allowed special characters + outside [] → one or more occurrences Real-world use: In form validation, this ensures an email has a valid local part before the @. Allows: john.doe@domain.com, user_name+tag@company.in Prevents: @domain.com, @ Key takeaway: Regex symbols are context-sensitive — the same operator (+) behaves differently depending on where it’s used. Understanding this makes regex clearer and more reliable. #Regex #InputValidation #DataScience #Python #Guvi
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