Day 39 of #100DaysOfCode 💻🔥🚀 Problem: Number of Arithmetic Slices ➕📈 💡 My Intuition: Imagine you’re tracking a sequence of numbers — if the difference between consecutive elements stays constant, it forms an arithmetic slice. Initially, I solved it using a difference array to find equal gaps, but later realized it can be done much more elegantly by just keeping two counters: curr → tracks current streak of arithmetic slices total → keeps cumulative count of all slices Whenever you find three numbers forming an arithmetic pattern, increment curr and add it to total. If the pattern breaks, reset curr to 0 and continue. ⚙️ Takeaway: Optimization isn’t always about writing more code — sometimes, it’s about recognizing a simple hidden pattern that makes the logic effortless ⚡ ✨ Keep learning. Keep refining. Every optimized line sharpens your thinking 💪🔥 #Day39 #100DaysOfCode #LeetCode #DSA #Java #CodingJourney #ProblemSolving #KeepPushing #GrindNeverStops
Optimizing Arithmetic Slices with Two Counters
More Relevant Posts
-
🌳 Day 36/100 ✅ Preorder Traversal of Binary Tree Today I solved the Preorder Traversal problem using recursion. In this traversal method, the order of visiting nodes is simple yet powerful: 👉 Root → Left → Right This problem helped me understand how recursion can naturally handle tree structures by breaking the problem into smaller subproblems. At each recursive call, we visit the root node first, then move to the left subtree, and finally to the right subtree — making the traversal flow smooth and logical. 💡 Key Takeaways: Preorder traversal always starts from the root. Recursion simplifies complex tree navigation into cleaner and readable logic. Visualizing the function call stack helps to truly understand the flow of recursion. Every day, I’m realizing how recursion is not just a coding tool — it’s a way to think step-by-step through structured problems. 🌱 #Day36 #DSA #CodingJourney #BinaryTree #PreorderTraversal #Recursion #ProblemSolving #LearningEveryday #100DaysOfCode #Java
To view or add a comment, sign in
-
-
🧩 Day 78 of #100DaysOfCode Challenge 🧩 📘 LeetCode 56 — Merge Intervals Topic: Arrays & Sorting Today’s problem was about merging overlapping intervals — a real test of logical thinking and array manipulation skills! 💡 Problem Summary: Given multiple intervals, the goal is to merge all overlapping ones and return a list of non-overlapping intervals that cover all ranges in the input. ⚙️ Approach (Brute + Optimized): 1️⃣ Sort all intervals based on their start value. 2️⃣ Compare the current interval with the previous one: If they overlap, merge them by updating the end time. If not, add the previous interval to the result. 3️⃣ Continue until all intervals are processed. 🧠 Key Learning: Sorting simplifies overlapping detection. Interval-based problems help strengthen array and logic handling. Real-world application: scheduling problems and timeline merging! ✨ Each problem is another step toward mastering patterns in DSA. #Day78 #LeetCode #100DaysOfCode #Java #DSA #ProblemSolving #WomenInTech #CodingJourney #Arrays #Sorting
To view or add a comment, sign in
-
-
🚀 Problem 2: Reverse Integer 💡 Leetcode Problem No: 7 Today, I solved an interesting Leetcode-style problem that involves reversing an integer — while handling tricky cases like integer overflow 🔄 ✨ Challenge: Given an integer x, reverse its digits and return the reversed number. If reversing x causes the value to go outside the signed 32-bit integer range, return 0. 💻 Key Learnings: 🔹 Used Math.abs(x) to handle negatives elegantly 🔹 Applied overflow check using: if (rev > (Integer.MAX_VALUE - d) / 10) 🔹 Mastered modulus (%) and division (/) logic for digit extraction 🔹 Ensured both positive and negative numbers are correctly reversed 💙 Tip: Always consider edge cases and overflow conditions when working with integer manipulation problems. #Java #Coding #LeetCode #ProblemSolving #JavaDeveloper #ProgrammingChallenge #LeetcodeCoding
To view or add a comment, sign in
-
-
📌 Day 51/100 – Longest Word in Dictionary (LeetCode 720) 🔹 Problem: Given an array of words, find the longest word that can be built one character at a time by other words in the array. If multiple results exist, return the lexicographically smallest one. 🔹 Approach: Built a Trie structure to store all words. Used DFS traversal to explore all valid prefixes (where every prefix forms a valid word). Updated the answer when a longer or lexicographically smaller valid word was found. 🔹 Key Learning: Deepened understanding of Trie traversal with DFS. Practiced combining lexicographical comparison with prefix validation. Reinforced prefix-based word-building logic efficiently. 🔹 Complexity: Time: O(N × L) — N = number of words, L = average word length Space: O(26 × N × L) — for Trie storage #Day51Of100 #LeetCode720 #100DaysOfCode #Java #DSA #Trie #DFS #ProblemSolving #CodingChallenge #Strings #DataStructures #CodingJourney #KeepLearning
To view or add a comment, sign in
-
-
🎯 Day 12 – Check if a String is Palindrome Today’s DSA challenge focuses on verifying whether a given string reads the same backward and forward — a fundamental problem that strengthens your understanding of string manipulation and logical thinking. 💡 Key Learning: Small problems often reveal big insights — palindrome checking teaches precision, clean iteration, and boundary control. 🧠 Concepts Used: Strings Two-pointer technique Character comparison ⏱️ Time Complexity: O(n) 💾 Space Complexity: O(1) 📘 Each problem reinforces how small logic improvements can lead to efficient, readable code. #Day12 #DSA #Java #Strings #KeepLearning #IntelliJ
To view or add a comment, sign in
-
-
✅ Day 68 of LeetCode Medium/Hard Edition Today’s challenge was “Number of Ways to Form a Target String Given a Dictionary” — a brilliant Dynamic Programming and Combinatorics problem that tests precision in transitions and precomputation logic 🧩⚙️ 📦 Problem: You’re given an array of equal-length strings words and a target string target. You must form target from left to right by picking characters from the columns of words under these rules: 1️⃣ Once you use column k from any word, all columns ≤ k in every word become unusable. 2️⃣ You can use multiple characters from the same word, respecting column progression. Return the number of ways to form target modulo 1e9 + 7. 🔗 Problem Link: https://lnkd.in/gns9CwWa ✅ My Submission: https://lnkd.in/g7bsgZq9 💡 Thought Process: This problem is a clever mix of frequency compression and DP memoization. We precompute a frequency table freq[26][m], where each cell represents how many words contain a given letter at column m. Then, using recursion with memoization: 🎯 At each step (i, j) Either use freq[target[i]][j] if it exists → multiply by ways for the next position (i+1, j+1) Or skip the current column → move to (i, j+1) The recurrence relation: dp[i][j] = freq[target[i]][j] * dp[i+1][j+1] + dp[i][j+1] All computations are done modulo 1e9 + 7. ⚙️ Complexity: ⏱ Time: O(26 * n + t * m) — efficient due to frequency precomputation 💾 Space: O(t * m) — for memoized DP table 💭 Takeaway: This challenge reinforced how precomputation and state optimization can transform a seemingly exponential recursion into an elegant polynomial-time solution 🚀 #LeetCodeMediumHardEdition #100DaysChallenge #DynamicProgramming #Combinatorics #ProblemSolving #Java #CodingChallenge #DSA
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟏𝟖 𝐨𝐟 #50DaysOfDSA 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝟑𝟐𝟐𝟖 — 𝐌𝐚𝐱𝐢𝐦𝐮𝐦 𝐍𝐮𝐦𝐛𝐞𝐫 𝐨𝐟 𝐎𝐩𝐞𝐫𝐚𝐭𝐢𝐨𝐧𝐬 𝐭𝐨 𝐌𝐨𝐯𝐞 𝐎𝐧𝐞𝐬 𝐭𝐨 𝐭𝐡𝐞 𝐄𝐧𝐝 (𝐌𝐞𝐝𝐢𝐮𝐦) 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐋𝐢𝐧𝐤 - https://lnkd.in/gu-Rnxuv 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 - https://lnkd.in/gvh4gS2z Ever thought how many times you can shift all '1's to the end of a binary string? That’s exactly what this problem challenges you to find! 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐒𝐮𝐦𝐦𝐚𝐫𝐲: You’re given a binary string s. In one operation, you can pick an index i where s[i] == '1' and s[i+1] == '0', and move that '1' to the right until it reaches the end or just before another '1'. Your goal find the maximum number of such operations possible. 𝐈𝐧𝐭𝐮𝐢𝐭𝐢𝐨𝐧: Instead of simulating the moves, observe that: Each '1' can contribute operations only when it faces zeros that form a boundary (zero-block end). So, every time we hit the last zero of a block, we can add the count of '1's before it. This insight keeps the solution linear O(n) time, O(1) space! 𝐓𝐚𝐤𝐞𝐚𝐰𝐚𝐲: Sometimes, the key to optimizing problems isn’t simulation, it’s pattern recognition. Spot the structure → derive the formula → simplify! #LeetCode #Java #CodingChallenge #DSA #ProblemSolving #Programming #50DaysOfCode
To view or add a comment, sign in
-
-
🚀 #DSAinJava #Day80 #300DayChallenge Another exciting day diving deeper into the #TUFWinterArc series by @takeUforward! 💪 Raj Vikramaditya Today’s focus was on tackling array-based logical challenges — sharpening problem-solving intuition and mathematical reasoning ⚡📊 🧠 Topics & Problems Covered: 1️⃣ Pascal’s Triangle 2️⃣ Majority Element (n/3 times) 3️⃣ 3–Sum Problem 💡 Key Learnings: 🔹 Understood how to generate Pascal’s Triangle efficiently using combinatorics and iterative logic. 🔹 Explored the Boyer–Moore Voting Algorithm to identify majority elements in O(n) time with O(1) space. 🔹 Solved the 3–Sum problem using the two-pointer approach — mastering sorting-based optimization to reduce time complexity from O(n³) ➡️ O(n²). 🔹 Strengthened debugging and pattern-recognition skills while working through edge cases. ⚡ Mindset Upgrade: Every problem solved today reinforced: ✅ The value of clean logic before code ✅ The power of mathematical insight in coding ✅ The importance of consistent, structured problem-solving 📂 All solutions available here: 👉 https://lnkd.in/deeXep9Q #TUFWinterArc #TakeUForward #Java #DSA #CodingJourney #Arrays #ProblemSolving #InterviewPreparation #LeetCode #CodeEveryday #ConsistencyWins
To view or add a comment, sign in
-
-
📌 Day 4/100 - Minimum Size Subarray Sum (LeetCode 209) 🔹 Problem: Given an array of positive integers and a target value, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. If there’s no such subarray, return 0. 🔹 Approach: Used the Sliding Window technique for an optimized solution: Initialize two pointers (low, high) and a running sum. Expand the window by moving high until the sum ≥ target. Once valid, shrink the window from the left to find the smallest subarray. Keep updating the minimum length throughout. This reduced the time complexity from O(n²) (brute force) to O(n). 🔹 Key Learning: Sliding Window is ideal for problems with contiguous subarrays. Optimization often comes from adjusting the window efficiently. Each problem strengthens logical flow and pattern recognition. Another step forward in mastering DSA and problem-solving consistency! ⚡ #100DaysOfCode #LeetCode #Java #ProblemSolving #DSA #CodingChallenge #SlidingWindow
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