🚀 [Day 12/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Count Subarrays With Fixed Bounds Today’s challenge really tested my understanding of subarray patterns and sliding window logic. The task was to count all subarrays where the minimum and maximum values are exactly equal to given bounds — minK and maxK. At first, my approach was brute force — I generated all possible subarrays, calculated the min and max for each, and increased the count if they matched. It worked, but with a painful O(n² + n) time complexity 😅 Then came the optimization breakthrough 💡 — I introduced three variables: badIndex → to mark positions where elements go out of range minIndex and maxIndex → to store the latest positions of valid min and max For each element, if it stayed within bounds, I could efficiently calculate how many valid subarrays ended at that index by using: count += Math.max(0, Math.min(minIndex, maxIndex) - badIndex) This reduced the complexity to O(n) and turned an expensive brute force into a clean, efficient linear pass ⚡ 🔍 Key Learnings: Identifying invalid states early (like badIndex) saves massive computation. Most subarray problems can be optimized using index tracking instead of recalculating repeatedly. Optimization isn’t about writing less code — it’s about thinking one step deeper 🧠 ✨ Small win — seeing how a few well-chosen variables can simplify a seemingly complex logic! #30DaysOfCode #Day12 #CodingChallenge #DSA #Educative #ProblemSolving #JavaScript #SlidingWindow #Optimization #KeepCoding #LearningJourney #Subarrays
"Optimized Subarray Counting with Sliding Window Logic"
More Relevant Posts
-
🚀 [Day 15/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Similar String Groups Today’s problem was all about identifying relationships between strings and grouping them based on their “similarity.” Two strings are considered similar if they differ in exactly two character positions — meaning you can swap those characters to transform one into the other. My intuition started with this core idea: 👉 If two strings differ by exactly two positions, they belong to the same group. To solve this, I approached the problem like a graph traversal challenge: 1️⃣ Consider each string as a node in a graph. 2️⃣ Create an edge between two nodes if the strings differ by exactly two characters. 3️⃣ Use DFS to explore all connected strings that form a similarity group. 4️⃣ Maintain a visited array to ensure each string is processed once. So for each unvisited string, I triggered a DFS call. That DFS marked all strings connected to it (all strings that were similar by 2-character difference). This naturally formed groups of similar strings — each connected component counted as one group. This problem beautifully reinforced how string similarity + graph connectivity can come together to form a clean and efficient solution 🧠✨ 🔍 Key Learnings: Many string problems hide an underlying graph structure — discovering it is half the solution. DFS is extremely powerful for grouping, clustering, and connectivity problems. A simple rule (differ by 2 characters) can create surprisingly complex group relationships. ✨ Small win — once I mapped the problem to graph traversal instead of brute-force comparisons, everything became much more intuitive! #30DaysOfCode #Day15 #CodingChallenge #Educative #DSA #GraphTheory #DFS #JavaScript #ProblemSolving #StringAlgorithms #LearningJourney #KeepCoding
To view or add a comment, sign in
-
🚀 [Day 10/30] Coding Challenge Journey with Educative 💡 Problem: Group Anagrams Today’s challenge was an interesting one — grouping words that are anagrams of each other. This problem pushed me to think deeply about string manipulation and hashing techniques. At first, I tried a frequency map approach — creating a character map for each string and comparing it with others. Though it worked, it wasn’t efficient (≈ O(n × k²) 😅). Then I optimized it by sorting each string and using the sorted value as a key in a hash map — grouping all strings with the same key together. This brought down the complexity to O(n × k log k) and made the logic much cleaner. Finally, I explored another variation — building a frequency-based signature for each string (like "a1b1c1") and using that as the key. This further improved the complexity to O(n × k) and avoided unnecessary sorting 🎯 🔍 Key Learnings: Choosing the right key representation is crucial for efficiency. Hash maps are powerful tools for grouping problems. Optimization is all about rethinking your data structure, not just your logic. ✨ Small win — seeing the same problem solved in 3 different ways reminded me that there’s always room to improve your first approach 💪 #30DaysOfCode #Day9 #CodingChallenge #DSA #Educative #ProblemSolving #JavaScript #HashMap #Anagrams #Optimization #KeepCoding #LearningJourney
To view or add a comment, sign in
-
🚀 Day 3 of my 30-Day Coding Challenge with Educative.io Today’s problem looked simple but had some fun twists. The task: given a binary string, find the number of steps to reduce it to 1 by repeatedly 1)dividing by 2 if even 2)adding 1 if odd. At first, I tried converting the binary to a number and then looping. Lesson learned — in JavaScript, large binary strings (length > 53 bits) overflow the Number limit. My approach worked for small inputs but failed for long ones. After debugging, I discovered a smarter pattern: 1)Work directly on the binary string from right to left. 2)Use a carry variable to simulate “add 1” operations. 3)Count operations based on whether the current bit + carry is odd or even. This avoids conversion and runs in O(n) time for strings up to 500 characters! Here’s what I took away from this challenge: Always think about data type limits (JS Number ≠ unlimited integer). Sometimes the best solution is bit-level simulation instead of numeric math. Debugging is just as valuable as solving. #JavaScript #CodingChallenge #Educative #LearningInPublic #DSA #ProblemSolving #SoftwareEngineering
To view or add a comment, sign in
-
✅ Day 5 of My 50-Day Coding Challenge Problem: Increasing Triplet Subsequence Difficulty: Medium Approach: The goal is to check if there exists a triplet (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. Instead of using nested loops (which would lead to O(n³) or O(n²) complexity), I used a greedy approach with two variables: 1. first → smallest number seen so far 2. second → second smallest number seen so far As we iterate through the array: 1. If the current number is smaller than or equal to first, update first. 2. Else if it’s smaller than or equal to second, update second. 3. Otherwise, if we find a number greater than both, we have an increasing triplet → return true. This works in O(n) time and O(1) space, making it efficient for large inputs. Why this approach? It avoids extra space and unnecessary comparisons by tracking only what matters: the smallest and second smallest values. Once we find a third number greater than both, the condition is satisfied. ✅ Complexity: 1. Time: O(n) 2. Space: O(1) #LeetCode #CodingChallenge #DataStructures #Algorithms #ProblemSolving #CSharp #DotNet #Programming #ContinuousLearning #TechCommunity #DeveloperLife #SoftwareEngineering #LearningEveryday
To view or add a comment, sign in
-
-
🚀 [Day 13/30] Coding Challenge Journey with @Educative.io 💻 💡 Problem: Course Schedule Today’s challenge was all about dependency management — figuring out whether it’s possible to finish all courses given their prerequisites. Essentially, it’s a graph problem disguised as a real-world scheduling issue 🎓 At first, my intuition was to use DFS (Depth First Search) to detect cycles — because if there’s a cycle, you can’t complete all courses. But as I explored further, I realized there’s a more intuitive approach: Topological Sorting using BFS (Kahn’s Algorithm). Here’s how I approached it step by step: 1️⃣ Built a graph representation from the prerequisites list. 2️⃣ Calculated the in-degree (number of incoming edges) for each course. 3️⃣ Used a queue to process all nodes (courses) with zero in-degree — meaning no dependencies. 4️⃣ Repeatedly removed nodes from the queue, reducing the in-degree of dependent nodes. 5️⃣ If all nodes were processed successfully, it meant the course order was possible ✅ This method helped identify cycles efficiently and made the logic easy to reason about — truly a satisfying example of graph traversal in action 🧠 🔍 Key Learnings: Many real-world problems (like task scheduling or project dependencies) can be modeled as graphs. Topological Sort is a must-know technique for problems involving order and precedence. Sometimes, the cleanest logic comes from thinking in terms of relationships, not just data. ✨ Small win — once I saw the connection between course dependencies and graph theory, the problem instantly clicked! #30DaysOfCode #Day13 #CodingChallenge #Educative #DSA #JavaScript #GraphAlgorithms #TopologicalSort #ProblemSolving #LearningJourney #KeepCoding #ProgrammersLife
To view or add a comment, sign in
-
💡 DAY 30 & 31 — Practicing & Understanding Conditions & Loops Sheryians Coding School | Sheryians AI School These two days were full of practice and powerful new concepts in JavaScript! 💻 On Day 30, we had a practice session focused on: 🔹 Revising and practicing all types of Operators 🔹 Practicing Hoisting — understanding how JavaScript moves declarations to the top 🔹 Exploring Function Hoisting — learning how function declarations are accessible even before they are defined It was a great hands-on day that helped me connect theory with real code. 🧠 Then came Day 31, where we started learning about Conditions and Loops — two very important pillars of programming. In Conditions, we learned: ✨ if, else if, else, switch, and ternary operators — how they control the flow of a program based on logic and decisions. Then we moved to Loops, and I realized how important they are in computer science — They make it possible to repeat tasks automatically instead of writing the same code multiple times. I learned that loops are mainly of two types based on their use case: 1️⃣ Straightforward Loops — where the value and output remain the same, e.g., printing “Sheryians” five times. 2️⃣ Dynamic Loops — where the values keep changing, e.g., printing numbers from 1 to 10. It was really fun understanding how loops make programs efficient and reduce repetition. 🚀 Every session adds a new layer to my understanding of JavaScript — from logic to execution! Instructor: Harsh Vandana Sharma #Day30 #Day31 #Cohort2_0 #JavaScript #FrontendDevelopment #WebDevelopment #LearningJourney #CodingLife #Hoisting #Loops #Conditions #SheryiansCodingSchool
To view or add a comment, sign in
-
-
Day 32 | Cohort 2.0 Journey Yesterday’s session was focused on understanding operators in JavaScript by Harsh Vandana Sharma from Sheryians Coding School, which are the real tools behind every calculation, condition, and logic we write. 📘 Covered Topics: 🔹 Arithmetic Operators → +, -, *, /, %, ** 🔹 Assignment Operators → =, +=, -=, etc. 🔹 Comparison Operators → ==, ===, !=, >, <, >=, <= 🔹 Logical Operators → &&, ||, ! 🔹 Ternary Operator → A short & smart way to write conditions 🔹 Type Operators → typeof, instanceof Learning how these work together really helps in writing cleaner, smarter code 💡 #Day32 #JavaScript #Operators #WebDevelopment #LearningJourney #FrontendDeveloper #SheryiansCodingSchool #Cohort2
To view or add a comment, sign in
-
🚀 [Day 11/30] Coding Challenge #30DaysOfCode 💡 Problem: Set Matrix Zeroes Today’s challenge tested my ability to balance time and space complexity efficiently — the task was to modify a matrix such that if any element is 0, its entire row and column should be set to zero. I explored multiple approaches before reaching an optimal one 👇 1️⃣ Brute Force Approach: I iterated through the entire matrix, and whenever I found a 0, I used a helper function to mark all elements in its row and column as -1. After completing this marking process, I did another pass to convert all -1 values to 0. ✅ Simple logic, but inefficient due to multiple passes and extra checks. 2️⃣ Using Extra Arrays: Next, I maintained two separate arrays — one for rows and one for columns — to keep track of which rows and columns should become zero. This improved clarity and avoided redundant marking. 🧠 Time Complexity: O(m × n) | Space Complexity: O(m + n) 3️⃣ Optimized In-Place Solution: Finally, I optimized further by using the first row and first column of the matrix itself as markers — eliminating the need for extra space. This reduced the space complexity to O(1) while maintaining O(m × n) time complexity. ✨ It was fascinating to see how a small shift in perspective (reusing the same matrix for storage) made the solution much more elegant and efficient. 🔍 Key Takeaways: Always aim to optimize space without compromising clarity. Sometimes, the best memory to use is the one already in use! 😄 Breaking a problem into stages (brute force → optimized) builds strong problem-solving intuition. eager for next day challenge with Educative. #Day11 #CodingChallenge #Educative #DSA #ProblemSolving #JavaScript #LearningJourney #KeepCoding #Matrix #Optimization #CleanCode
To view or add a comment, sign in
-
🔍Concepts in 60 Seconds: Ep-4 Ever wished you could reuse code instead of writing it again and again? That’s exactly what Inheritance in Object-Oriented Programming (OOP) allows! It’s the concept where one class (called the child or derived class) can inherit properties and behaviours from another class (called the parent or base class). This means the child class automatically gets access to all the variables and methods of its parent, and can even modify or extend them! ⁉️ Why it matters: -Promotes code reusability — no need to rewrite what already exists. -Encourages modular design — making maintenance and updates easier. -Establishes a clear hierarchy between general and specific classes. 💡 Types of Inheritance: Single Inheritance – One parent, one child. Multiple Inheritance – A class inherits from more than one parent. Multilevel Inheritance – A child becomes a parent for another class. Hierarchical Inheritance – Multiple classes inherit from a single parent. Hybrid Inheritance – A mix of the above types. ⚙️ In simple terms: Inheritance is like passing down traits — the child inherits the DNA of its parent class! 🧠 Next Wednesday: One function, many forms! We will dive into Polymorphism, the art of making code flexible, reusable, and smart. #ConceptsIn60Seconds #OOPS #Inheritance #CodeReusability #ProgrammingConcepts #ObjectOrientedProgramming #TechLearning #WednesdayWisdom #SoftwareDevelopment #LearnWithNatlie #StudentLearning #CSFundamentals #TechWednesdays #CSEConcepts #OOPSeries #CodingConcepts #ProgrammingBasics #CodeBetter
To view or add a comment, sign in
-
-
🚀 Day 30 of My COHORT 2.0 Development Journey Sheryians Coding School Topic: Operators in JS Today’s class focused on one of the most important foundations of JavaScript: Operators. Operators help us perform calculations, assign values, compare data, and write logical conditions - basically the backbone of any program. Here’s what we covered: 🔢 1️⃣ Arithmetic Operators Used for basic mathematical operations: + , - , * , / , % , ** These help us calculate values and perform number-based logic. 📝 2️⃣ Assignment Operators Used to assign or update variable values: = , += , -= , *= , /= , %= They make updating values shorter and cleaner. ⚖️ 3️⃣ Comparison Operators Used to compare two values: == , === , != , !== , > , < , >= , <= These return true/false and are essential for conditions, loops, and decision-making. 🔐 4️⃣ Logical Operators Used to combine multiple conditions: && (AND) || (OR) ! (NOT) These help in creating complex logical checks in real-world applications. 🧠 Key Takeaway: Operators may look simple, but they form the base of every function, condition, calculation, and logic flow in JavaScript. Today’s class helped me understand how they work behind the scenes and how to use them effectively while building real projects. #JavaScript #Cohort2 #WebDevelopment #FrontendDevelopment #CodingJourney #OperatorsInJS #LearnByDoing #SheriyansCodingSchool
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