Problem Solved: Maximum Subarray ✔️ 210 / 210 test cases passed ✔️ Runtime: 2 ms ✔️ Beats 70.71% submissions Key Idea: This problem is a classic application of "Kadane’s Algorithm". Instead of checking every possible subarray (which would take O(n^2), Kadane’s algorithm takes a smarter approach. As we iterate through the array: Keep a running sum of the current subarray. Update the maximum sum whenever a larger value is found. If the running sum becomes negative, reset it to 0 because a negative prefix will only reduce future sums. Complexity: Time Complexity: O(n) Space Complexity: O(1) Every time I revisit these classic algorithms, it reminds me how elegant good algorithm design can be. #LeetCode #DSA #KadaneAlgorithm #JavaScript #CodingJourney #ProblemSolving #LearnInPublic
Devesh Shukla’s Post
More Relevant Posts
-
Solved Linked List Cycle II using Floyd’s Cycle Detection Algorithm (Tortoise and Hare). The approach uses two pointers moving at different speeds to first detect the cycle and then identify the exact node where the cycle begins. Once the pointers meet, resetting one pointer to the head and moving both one step at a time leads them to the cycle start node. Key Takeaways: Efficient cycle detection in linked lists O(n) time complexity O(1) space complexity Classic two-pointer technique #DataStructures #Algorithms #LinkedList #JavaScript #LeetCode #ProblemSolving #CodingJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
Implemented an efficient solution to the Dutch National Flag problem in JavaScript, sorting an array of 0s, 1s, and 2s in a single pass using the three-pointer approach. Achieved optimal O(n) time complexity with constant O(1) space, demonstrating in-place array manipulation and clean pointer logic. #JavaScript #DSA #Algorithms #Coding #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
Day 17 of #LeetCodeDaily Problem: Sort Colors (Medium) Given an array with values 0, 1, 2 representing colors (Red, White, Blue), sort them in-place without using any built-in sort. 🔍 My Approach: Use Dutch National Flag Algorithm (3-pointer approach) Maintain three pointers: low → position for 0 mid → current element high → position for 2 Algorithm: If element is 0 → swap with low, move both low & mid If element is 1 → just move mid If element is 2 → swap with high, move high only This ensures: Left side → all 0s Middle → all 1s Right side → all 2s ⏱ Time: O(n) 📦 Space: O(1) Single pass + in-place sorting makes it optimal 🚀 💡 Learning: When array has limited values → think partitioning Key insight → don’t move mid when swapping with high Always re-check swapped elements Classic problem to test pointer manipulation skills #ProblemSolving #LeetCode #JavaScript #DSA #Algorithms #Array #InterviewPrep #CodingJourney #30DaysDSAChallenge #LearningInPublic
To view or add a comment, sign in
-
-
Implemented the Bubble Sort algorithm in JavaScript to sort an array in ascending order using a simple comparison and swapping technique. Demonstrates a fundamental sorting approach with O(n²) time complexity, ideal for understanding core algorithm concepts. #JavaScript #DSA #Algorithms #Coding #WebDevelopment
To view or add a comment, sign in
-
-
🚀 𝗡𝗲𝘄 𝗣𝗥 𝗠𝗲𝗿𝗴𝗲𝗱 I recently tackled a fun logical puzzle: how to move all zeroes to the end of an array while maintaining the relative order of the non-zero elements. This challenge, which I've documented in my latest PR (https://lnkd.in/dSXWnSES), really tested my ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 to array manipulation. My solution involved iterating through the array and using a pointer to keep track of the position where the next non-zero element should be placed. This allowed me to effectively "compress" the non-zero elements to the front, implicitly leaving zeroes at the end. During the process, I leaned on dry runs to trace the array's state and visualize the pointer movements. When I hit a snag, the debugger was invaluable for stepping through the logic line by line and understanding exactly where my assumptions were off. A key takeaway for me was the power of in-place modification and how a well-placed pointer can simplify array problems significantly. How do you ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 similar array manipulation challenges? Share your strategies below! 📦 Repo: https://lnkd.in/dSXWnSES #ArrayManipulation #JavaScript #Algorithms #ProblemSolving #CodingChallenge #DataStructures #InPlaceAlgorithms #LogicalReasoning #SoftwareDevelopment #LeetCodeStyle
To view or add a comment, sign in
-
-
rag-from-scratch by Patric Gutersohn implements RAG in plain JavaScript … no LangChain, no abstractions. Cosine similarity, recursive character splitting, BM25 + vector hybrid search, query preprocessing, all written from scratch with node-llama-cpp. The in-memory vector store makes the full pipeline traceable in a debugger. Starts at a 70-line end-to-end example and builds up to hybrid retrieval and reranking. Rare to find a repo where every function is explained instead of imported. #rag #javascript #nodellama #vectorsearch
To view or add a comment, sign in
-
-
🧠 Day 178 — Next Greater Element 📈 Today I revised one of the most important stack pattern problems in DSA: Next Greater Element. The goal is straightforward but very useful: ✔ For every element, find the next greater element on its right ✔ If no greater element exists → return -1 This problem is a great example of combining: • Stacks • Efficient traversal techniques • Hash map lookups for fast queries Understanding this pattern unlocks solutions to many other problems like Daily Temperatures, Stock Span, and Largest Rectangle in Histogram. 🚀 DSA Journey Update Slowly building strong foundations in Stacks, Dynamic Programming, and Trees. Consistency is the real game. #DSA #Stacks #MonotonicStack #JavaScript #CodingJourney #LeetCode #ProblemSolving #ConsistencyWins
To view or add a comment, sign in
-
-
🚀 LeetCode Problem Solved – Single Number Solved the Single Number problem on LeetCode using JavaScript with an optimized bit manipulation approach. 📌 Problem Statement Given an array where every element appears twice except for one, the task is to find the element that appears only once. 💡 Approach Instead of using extra space like hash maps, I used the XOR trick. Key properties of XOR: • a ^ a = 0 (same numbers cancel each other) • a ^ 0 = a (XOR with zero keeps the number unchanged) By XORing all elements in the array: Duplicate numbers cancel out The unique number remains as the final result ⚡ Complexity 🔹 Time Complexity: O(n) – Traverse the array once 🔹 Space Complexity: O(1) – No extra data structures used #leetcode #javascript #dsa #bitmanipulation #codingpractice #softwareengineering #algorithms
To view or add a comment, sign in
-
-
🚀 Day 23 of #60DaysOfDSA Today I implemented Quick Sort, a powerful Divide & Conquer algorithm used for sorting. 🔍 What I learned: Quick Sort works by selecting a pivot element It partitions the array into: Elements smaller than pivot Elements greater than pivot Then recursively sorts both parts ⚡ Key Insight: “Partitioning is the heart of Quick Sort.” Even a small mistake in index handling or swapping can completely break the logic. 💻 Key Concepts Covered: ✔️ Pivot selection (last element) ✔️ Partition logic (Lomuto method) ✔️ Recursion ✔️ In-place sorting 🧠 Takeaway: Quick Sort is not just about writing code, it’s about understanding how elements move and how recursion divides the problem. Consistency > Perfection 🚀 One step closer to becoming better every day! #DSA #QuickSort #CodingJourney #JavaScript #ProblemSolving
To view or add a comment, sign in
-
-
🚀 𝗡𝗲𝘄 𝗣𝗥 𝗠𝗲𝗿𝗴𝗲𝗱 I recently tackled the challenge of reversing an array in-place. The core 🧩 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 was to modify the original array directly without creating a new one, which requires careful index management. To solve this, I implemented the two-pointer technique in JavaScript. I used one pointer starting at the beginning of the array and another at the end. I then swapped the elements pointed to by these pointers and moved them towards the center until they met or crossed. This ⚙️ 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵 ensures O(1) space complexity. My 🐞 𝗗𝗲𝗯𝘂𝗴𝗴𝗶𝗻𝗴 𝗣𝗿𝗼𝗰𝗲𝘀𝘀 involved dry runs to trace the pointer movements and element swaps. Visualizing the array's state at each step was crucial. I also occasionally used the debugger to step through the code and confirm my understanding of the logic. A 📚 𝗞𝗲𝘆 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 from this exercise was the power of in-place algorithms for optimizing memory usage, especially when dealing with large datasets. You can see the implementation in my latest PR: https://lnkd.in/d5rAw_CN What are your favorite in-place algorithms or techniques? 📦 Repo: https://lnkd.in/d5rAw_CN #DataStructures #Algorithms #JavaScript #TwoPointerTechnique #ProblemSolving #InPlaceAlgorithm #CodingChallenge #SoftwareDevelopment #ArrayManipulation
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