Brute force works… But it’s not always smart ❌ This problem is a perfect example 👇 👉 Find maximum sum of subarray of size K Naive approach: Check all windows → O(n × k) Optimized approach: Use Sliding Window → O(n) 💡 What changes? You stop repeating work. Instead of recalculating sum every time: → Subtract old element → Add new element That’s it. 👉 Less loops = More efficiency #ProblemSolving #DSA #Coding #Developers
Optimize Subarray Sum with Sliding Window
More Relevant Posts
-
Time for a C-Programming Deep Dive! Pointers are often where the gap between "knowing" C and "mastering" C becomes clear. Can you predict the exact output of this code without running it in a compiler? The Challenge: #include <stdio.h> int main() { int arr[] = {10, 20, 30, 40, 50}; int *ptr = arr; printf("%d, ", *ptr++); printf("%d, ", *++ptr); printf("%d, ", ++*ptr); printf("%d", (*ptr)++); return 0; } How to participate: Work out the logic for each printf statement. Drop your answer in the comments below. Explain why the third and fourth outputs are particularly tricky! I’ll be liking the correct answers and posting the full technical breakdown of the operator precedence involved in 24 hours. Let's see who gets it 100% right! 🎯 #CProgramming #EmbeddedSystems #VLSI #CodingChallenge #SoftwareEngineering #Pointers #ProgrammingQuiz
To view or add a comment, sign in
-
Most dev tool sites want your email, your data, and your soul before you can generate a QR code. Delphi.tools is the opposite. QR generators, color converters, SVG optimizers, regex testers, favicon generators: all in one place. No login. No tracking. No nonsense. Bookmark it. You'll use it more than you think. #programming #coding #computerscience
To view or add a comment, sign in
-
🚀 Leveling up my DSA skills: Mastering the Sliding Window! I recently tackled the "Longest Substring Without Repeating Characters" problem on LeetCode using C++. This was a great exercise in optimizing time complexity and understanding how to manage dynamic windows within a string. 💡 The Approach To solve this efficiently, I used the Sliding Window technique combined with an unordered_map: Expansion: The high pointer expands the window by adding characters to the frequency map. Contraction: If the number of unique characters in the map is less than the window size ($f.size() < k$), it means we have a duplicate. The low pointer then slides forward, removing characters until the window is valid again. Efficiency: This approach ensures we traverse the string in $O(n)$ time, which is much better than a brute-force $O(n^2)$ search. #LeetCode #CodingJourney #CPP #DataStructures #Algorithms #SoftwareEngineering #ProblemSolving #SlidingWindow #Programming
To view or add a comment, sign in
-
-
my weekend rabbit hole this time: does Box<dyn Trait> actually matter in hot loops? built a pipeline with 8 operations running over 10 million floats. one version with Box<dyn Processor>, one with generics. same logic, same values, same machine. 118ms vs 13ms. WILD the vtable itself isn't even the problem, 2ns per call, genuinely irrelevant. the real issue is what it stops the compiler from doing. with dyn Trait it can't inline across steps, can't vectorize, can't use SIMD. just calls function pointers one by one. with generics it knows every type at compile time and goes crazy, fuses all the operations, auto-vectorizes the whole loop, multiple elements per cycle. same code. the compiler just had more information and used it. worth auditing if you have Box<dyn Trait> in anything performance sensitive. sometimes you need the flexibility. but if the types are known at compile time, you might be paying 10x for an abstraction you don't actually need repo below if you want to run it on your machine https://lnkd.in/drtUJTwq #rust #programming #performance #systems #lowlevel #softwaredevelopment #rustlang #softwareengineering #coding #techcommunity
To view or add a comment, sign in
-
-
🧠 One small mistake can break your entire logic. Today I learned this while solving a grid problem 👇 💻 LeetCode #1559 — Detect Cycles in 2D Grid At first glance, it looks like a simple DFS problem… But there’s a catch ⚠️ 🔍 Common mistake developers make: 👉 “If I visit an already visited cell → cycle exists” Sounds correct… but it’s NOT ❌ 🚀 My Approach (DFS + Parent Tracking): Traverse the grid using DFS Move in 4 directions (up, down, left, right) Only move to cells with the same character 👉 While moving, I track the parent cell 💡 Key Logic: If I reach a cell that is: Already visited AND not the parent 👉 Then a cycle exists ✅ ⚙️ Why parent check is important? Because going back to the previous cell is normal 👉 It should NOT be treated as a cycle 🧠 Takeaway: In DSA, logic rarely fails… 👉 Edge cases do 🔥 The difference between wrong and correct solution is often just one condition Have you ever fixed your solution by changing just 1 line? 😄 #LeetCode #DSA #Algorithms #Programming #Debugging #ProblemSolving #Developers #CodingJourney
To view or add a comment, sign in
-
-
What is a domain name? A domain name is the human-readable address of a website that people type into a browser to visit it, such as example.com. Instead of remembering a long string of numbers called an IP address, the domain name makes it easy to find and access websites. When you enter a domain name, the internet uses a system called DNS (Domain Name System) to translate it into the correct server location where the website is hosted. Domain names are unique, meaning no two websites can have the same one, and they help give your site an identity online. #webdeveloper #tech #coding #programming
To view or add a comment, sign in
-
-
Spent hours debugging a bug that made zero sense. A simple condition was failing: 4 / 2 == 2 Logically correct. Mathematically correct. Still… failing. No crashes. No obvious errors. Just a silent mismatch breaking the flow. Out of frustration, I printed the value instead of trusting it. 👉 1.999999995 That’s when things clicked. It wasn’t a logic bug. It was a precision problem. Floating-point arithmetic doesn’t guarantee exact values — numbers are stored as binary approximations. And sometimes, that “2” you trust is just… slightly off. That tiny difference was enough to fail an equality check: if (result == 2) → false The fix? ✔️ Avoid direct comparison of floating numbers ✔️ Use a tolerance (epsilon) for comparisons ✔️ Or switch to precise types where exact values matter That day debugging reminded me: The scariest bugs aren’t the ones that crash. They’re the ones that look perfectly correct. And sometimes… 4 / 2 isn’t 2. #SoftwareEngineering #Debugging #Programming #Flutter #Android #Bugs
To view or add a comment, sign in
-
-
SOLID PRINCIPLE PART - 8 WHAT IS LSP OR MEANING OF ‘L’? L — Liskov Substitution Principle 👇 👉 Child class should behave like parent ❌ Example: Bird → Fly() Ostrich → cannot fly ❌ 👉 Breaks system ✔ Fix: Separate flying behavior 👉 Correct inheritance = stable system 🔔 Follow me for more: TechClarityWithVijay 👤 Vijay Narayan Mishra https://lnkd.in/gaWaDqZj #dotnet #softwareengineering #backenddeveloper #cleanarchitecture #coding #developers #systemdesign #TechClarityWithVijay
To view or add a comment, sign in
-
-
The code solves a problem finding maximum subarray sum in an array. What i have done here solve the problem properly. But here the new problem is the code is not optimized. It becomes huge when the input is big. Here, Time Complexity = O(n²) Space Complexity = O(1)/constant It gets time limit exceeded when the input is big. So when we run this code on a server, it demand a huge CPU power and increases cost and decreases efficiency. This shows the need of optimal solution. That's we need to learn how to write code optimally. There's an algorithm that solves this problem optimally. Can you guess that? If you can, comment below. This problem is from Leetcode-53. #programming #leetcode #coding
To view or add a comment, sign in
-
-
A Quick Guide to HTTP Status Codes Too often, we treat HTTP codes as an afterthought. Here’s a developer's premium cheat sheet that clearly defines the most common 2xx, 4xx, and 5xx series codes. A great resource to keep bookmarked or pinned. #Coding #WebDeveloper #FullStack #TechTips #DevTips
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