Day 33/100 – #100DaysOfCode 🚀 Solved LeetCode #1480 – Running Sum of 1d Array (Python). Today I practiced prefix sum logic to compute the running sum of an array. Approach: 1) Initialize an empty list to store the running sum. 2) Maintain a variable sum = 0. 3) Traverse the array and keep adding each element to sum. 4) Append the updated sum to the result list. 5) Return the final running sum array. Time Complexity: O(n) Space Complexity: O(n) Understanding prefix sums helps solve many array problems efficiently 💪 #LeetCode #Python #DSA #Arrays #PrefixSum #ProblemSolving #100DaysOfCode
LeetCode 1480: Running Sum of 1D Array in Python
More Relevant Posts
-
Day 42/100 – #100DaysOfCode 🚀 Solved LeetCode #2574 – Left and Right Sum Differences (Python). Today I practiced prefix sum logic to calculate the absolute difference between left and right sums for each index. Approach: 1) Calculate the total sum of the array. 2) Initialize leftSum = 0. 3) Traverse the array. 4) For each index, compute rightSum = total - leftSum - nums[i]. 5) Calculate the absolute difference and append it to the result. 6) Update leftSum by adding nums[i]. Time Complexity: O(n) Space Complexity: O(n) Understanding prefix sum helps solve problems efficiently 💪 #LeetCode #Python #DSA #Arrays #PrefixSum #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 53/100 – #100DaysOfCode 🚀 Solved LeetCode #125 – Valid Palindrome (Python). Today I practiced string cleaning and validation to check whether a given string is a palindrome. Approach: 1) Traverse the string and keep only alphanumeric characters. 2) Convert all characters to lowercase. 3) Build a cleaned string. 4) Compare the string with its reverse. 5) If both are equal, return True; otherwise, return False. Time Complexity: O(n) Space Complexity: O(n) Learning how preprocessing simplifies string problems 💪 #LeetCode #Python #DSA #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 50/100 – #100DaysOfCode 🚀 Solved LeetCode #28 – Find the Index of the First Occurrence in a String (Python). Today I practiced string matching using a brute-force approach to find the first occurrence of a substring. Approach: 1) Traverse the main string (haystack). 2) For each index, try to match the substring (needle). 3) Compare characters one by one. 4) If all characters match, return the starting index. 5) If mismatch occurs, break and move to the next index. 6) If no match is found, return -1. Time Complexity: O(n × m) Space Complexity: O(1) Understanding basic string matching techniques step by step 💪 #LeetCode #Python #DSA #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 46/100 – #100DaysOfCode 🚀 Solved LeetCode #2733 – Neither Minimum nor Maximum (Python). Today I practiced sorting and simple array logic to find any element that is neither the minimum nor the maximum in the array. Approach: 1) Sort the array. 2) Check the length of the array. 3) If the size is less than or equal to 2, return -1 (no valid element exists). 4) Otherwise, return the second element as it will be neither min nor max. Time Complexity: O(n log n) Space Complexity: O(1) Understanding how sorting simplifies boundary-based problems 💪 #LeetCode #Python #DSA #Arrays #Sorting #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 38/100 – #100DaysOfCode 🚀 Solved LeetCode #2011 – Final Value of Variable After Performing Operations (Python). Today I practiced string handling and simple iteration to compute the final value after a series of operations. Approach: 1) Initialize a variable x = 0. 2) Traverse through each operation in the list. 3) If the operation contains "++", increment x by 1. 4) Otherwise, decrement x by 1. 5) Return the final value of x. Time Complexity: O(n) Space Complexity: O(1) Simple logic but great practice for handling strings and loops 💪 #LeetCode #Python #DSA #Strings #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 39/100 – #100DaysOfCode 🚀 Solved LeetCode #2215 – Find the Difference of Two Arrays (Python). Today I practiced set operations to efficiently find distinct elements between two arrays. Approach: 1) Convert both arrays into sets to remove duplicates. 2) Find elements present in nums1 but not in nums2 using set difference. 3) Find elements present in nums2 but not in nums1. 4) Convert both results back to lists. 5) Return the final list of differences. Time Complexity: O(n + m) Space Complexity: O(n + m) Understanding how set operations simplify comparison problems 💪 #LeetCode #Python #DSA #Sets #Arrays #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 4 – Python Deep Dive 🚀 Topic: Mutable vs Immutable Immutable: int, string, tuple Mutable: list, dictionary Example: x = "hello" x[0] = "H" ❌ (error) 👉 Key takeaway: Immutable objects cannot be changed after creation. This impacts memory and performance. #Python #DeveloperThinking
To view or add a comment, sign in
-
-
Here's a Python dictionary merge challenge from @dontmisstmr — can you get it right without running the code? dict1 = {"name": "Alice", "age": 25} dict2 = {"city": "Noida", "age": 26} merged = dict1 | dict2 print(merged) The | operator was introduced in Python 3.9. When both dicts share a key, which value wins? Drop your answer in the comments! #Python #SoftwareDevelopment #CodingChallenge #ProgrammingTips #TechCommunity
To view or add a comment, sign in
-
🚀 Day 2 — Python Journey Continuing with Python, today I focused on integer operations. 📌 What I learned: - Integer declaration - Addition, subtraction, multiplication - Division and modulus (remainder) - Power operation - Operator precedence (which operation runs first) 💡 What stood out: Understanding operator precedence is really important — the same expression can give different results if you don’t know the order of execution. Also, modulus (%) is more useful than it looks (especially for problems and logic building). Trying to stay consistent and build strong basics step by step. #Day2 #Python #CodingJourney #Consistency #LearnInPublic
To view or add a comment, sign in
-
-
This one NumPy concept saved me hours of coding 👇 👉 Vectorization Earlier, I used loops for almost everything in Python. It worked… but it was slow and messy. Then I discovered this: Instead of processing data element by element, NumPy lets you operate on the entire array at once. Example: Adding 10 to every number Before (Python list): → loop through each element Now (NumPy): → one single line That’s it. This small shift leads to: - faster execution - cleaner code - better performance on large datasets The real change is in thinking: ❌ Think in loops ✅ Think in operations on data That’s when NumPy actually starts making sense. If you’re learning NumPy, focus on this concept early. #NumPy #Python #DataScience #DataEngineering #MachineLearning #CodingJourney #TechLearning
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