Day 11/100 — Coding Challenge Today’s problem was about identifying leaders in an array, which is a great exercise in understanding traversal from the right and maintaining a dynamic maximum. Problem: Find all elements in an array that are greater than or equal to every element to their right. Approach: Traverse the array from right to left. Keep track of the maximum element encountered so far. If the current element is greater than or equal to this max, it’s a “leader.” Reverse the collected list to maintain left-to-right order. This solution had a time complexity of O(n) and passed all 1111/1111 test cases with 100% accuracy. This challenge reinforced how scanning in reverse can simplify certain problems and eliminate extra computations. #100DaysOfCode #Java #DSA #ProblemSolving #CodingJourney
Identifying Leaders in an Array with Reverse Traversal
More Relevant Posts
-
🚀 Day 98 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Find Median in a Stream 🟡 Difficulty: Medium 🧠 Approach: Used two heaps (Priority Queues) — a Max-Heap for the left half and a Min-Heap for the right half of the numbers. For every new number in the stream: 1. Inserted it into the appropriate heap based on its value. 2. Balanced both heaps so that their sizes differ by at most one. Calculated the median: If heaps are of equal size → median = average of both top elements. If not equal → median = top of the larger heap. Stored each median value after every insertion. ⚡ Complexity: Time Complexity: O(N log N) → Each insertion and balancing operation takes log N. Space Complexity: O(N) → For storing elements in both heaps and the result list. 📊 Result: ✔️ 1113 / 1113 test cases passed 📈 Accuracy: 100% Finding the median dynamically using heaps — an elegant real-time data structure application! 💪 #Day98 #gfg160 #GeeksforGeeks #Java #Heap #PriorityQueue #Median #ProblemSolving #DSA #CodingChallenge #LearnByDoing #TechJourney #160DaysOfCode #DailyDSA #Consistency #SoftwareEngineering #CodingJourney #StJosephsInstituteOfTechnology
To view or add a comment, sign in
-
-
🚀 Day 111 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Longest String Chain 🟡 Difficulty: Medium 🧠 Approach: Used Dynamic Programming + Sorting to efficiently find the Longest Possible Word Chain. 🔹 Step 1: Sort all words by their length — shorter words come first. 🔹 Step 2: For each word, generate all possible predecessors by removing one character at a time. 🔹 Step 3: Use a HashMap dp where dp[word] represents the longest chain ending at that word. 🔹 Step 4: If a predecessor exists in the map → dp[word] = max(dp[word], dp[predecessor] + 1) Else → Start a new chain with length 1. 🔹 Step 5: Keep track of the global maximum chain length throughout the iteration. ✅ This approach efficiently checks possible chains by reusing previous computations instead of recomputing subsequences. ⚡ Complexity: 🕒 Time Complexity: O(N * L²) → For each word (N), we generate and check up to L possible predecessors. 💾 Space Complexity: O(N) → For the DP map storing longest chain lengths. 📊 Result: ✔️ 1114 / 1114 test cases passed 📈 Accuracy: 100% Dynamic Programming beautifully captures the “build-up” of word sequences — turning small steps into long, powerful chains! 💪 #Day111 #gfg160 #GeeksforGeeks #Java #DynamicProgramming #HashMap #Strings #ProblemSolving #DSA #CodingChallenge #LearnByDoing #160DaysOfCode #DailyDSA #SoftwareEngineering #CodingJourney #Consistency #StJosephsInstituteOfTechnology
To view or add a comment, sign in
-
-
🚀 Day 110 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Longest Increasing Subsequence (LIS) 🟡 Difficulty: Medium 🧠 Approach: Used an optimized Binary Search + Dynamic Programming (Patience Sorting) approach to find the length of the Longest Increasing Subsequence. 🔹 Created a temporary list temp to store the smallest possible tail values of increasing subsequences of various lengths. 🔹 For each element in the array: 1️⃣ Used binary search to find its correct position in temp. 2️⃣ If the element is greater than all elements in temp, append it (extend LIS). 3️⃣ Otherwise, replace the first element in temp that is greater than or equal to it (to maintain smallest possible tails). 🔹 The length of temp at the end gives the LIS length. ✅ Efficient and elegant — avoids the O(N²) DP approach by leveraging binary search! ⚡ Complexity: 🕒 Time Complexity: O(N log N) → Each element processed with binary search 💾 Space Complexity: O(N) → For the temp list 📊 Result: ✔️ 1111 / 1111 test cases passed 📈 Accuracy: 100% Finding structure in chaos — building the Longest Increasing Subsequence efficiently! 💪 #Day110 #gfg160 #GeeksforGeeks #Java #BinarySearch #DynamicProgramming #LIS #ProblemSolving #DSA #CodingChallenge #LearnByDoing #160DaysOfCode #DailyDSA #SoftwareEngineering #Consistency #CodingJourney #StJosephsInstituteOfTechnology
To view or add a comment, sign in
-
-
𝐃𝐚𝐲 𝟐𝟏 𝐨𝐟 #50DaysOfDSA 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐋𝐢𝐧𝐤 : https://lnkd.in/gzNm43Xx 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 : https://lnkd.in/gAXsPq4Q Today’s challenge was all about counting substrings efficiently — without generating them one by one. The problem? Given a binary string, find the number of substrings that contain only ‘1’s, modulo 1e9+7. 𝐊𝐞𝐲 𝐈𝐧𝐬𝐢𝐠𝐡𝐭: Instead of checking all substrings, simply count consecutive 1s. For every continuous segment of k ones, the number of valid substrings is: 𝐤 * (𝐤 + 𝟏) / 𝟐 But we optimize further by counting while we iterate. 𝐀𝐩𝐩𝐫𝐨𝐚𝐜𝐡: -> Maintain a running count of consecutive 1s -> Add that to the total whenever a 1 appears -> Reset when a 0 appears -> Handle large numbers using modulo 𝐓𝐢𝐦𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝐧) 𝐒𝐩𝐚𝐜𝐞 𝐂𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲: 𝐎(𝟏) #leetcode #dsa #java #coding #problemsolving #programming #learningeveryday #devcommunity #softwareengineering #100daysofcode #girlswhocode #problem solving
To view or add a comment, sign in
-
-
🚀 Day 12 of #50DaysOfLeetCodeChallenge 🚀 🧩 Problem 1260: Shift 2D Grid:: You are given a 2D grid of size m x n and an integer k. The task is to shift the grid k times. 💡 Approach: Flattened the 2D grid into a 1D array to simplify shifting. Calculated the effective shifts using k % totalElements to avoid redundant rotations. Created a new shifted array by mapping each element from the original flattened array to its new position. Converted the 1D shifted array back into a 2D array row by row. ✅ Efficient: O(m * n) ✅ Handles all edge cases, including k = 0 or k > total elements ✅ Clear and easy-to-follow logic 📚 Key Takeaways: Strengthened understanding of 2D to 1D mapping and vice versa. Learned how modular arithmetic helps in rotation problems. Improved skills in array transformations and index calculations. Huge thanks to Trainer Shishir chaurasiya and PrepInsta for constant guidance and motivation! 🙏 #50DaysOfLeetCodeChallenge #LeetCode #Java #ProblemSolving #CodingJourney #TechCommunity #KeepLearning #DSA
To view or add a comment, sign in
-
-
Day 4 of #50DaysOfDSA 𝐏𝐫𝐨𝐛𝐥𝐞𝐦: Check If Digits Are Equal in String After Operations 𝐏𝐫𝐨𝐛𝐥𝐞𝐦 𝐋𝐢𝐧𝐤 : https://lnkd.in/gM8Miz8e 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧 𝐋𝐢𝐧𝐤 : https://lnkd.in/gxDr6dCm 𝐂𝐨𝐧𝐜𝐞𝐩𝐭𝐬 𝐏𝐫𝐚𝐜𝐭𝐢𝐜𝐞𝐝: String manipulation, modulo operation, iterative transformations I solved 𝐋𝐞𝐞𝐭𝐂𝐨𝐝𝐞 𝟑𝟒𝟔𝟏, where we repeatedly transform a string of digits by summing consecutive pairs modulo 10 until only two digits remain. The task is to check if the final two digits are the same. Example: Input: "3902" → Output: true Input: "34789" → Output: false Simple problems with strings can be tricky when transformations are repeated multiple times. Always test step by step! #Java #LeetCode #Coding #Programming #DSA #Day4 #50DaysOfDSA #ProblemSolving
To view or add a comment, sign in
-
-
Day 104 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Max of Min for Every Window Size 🔴 Difficulty: Hard 🧠 Approach: Tackled one of the most conceptually rich stack problems — finding the maximum of minimums for every window size in an array. Here’s how I approached it: 1️⃣ For each element in the array, determined the previous smaller and next smaller elements using a stack. This helps find the window size where the current element is the minimum. 2️⃣ Stored the maximum of all minimums for each possible window size. 3️⃣ Updated results for smaller window sizes to ensure they carry forward the maximum possible values. This approach efficiently maps each element’s “span of influence” — a beautiful combination of monotonic stacks and window-based analysis ⚡ Complexity: 🕒 Time Complexity: O(N) → Each element is pushed and popped once. 💾 Space Complexity: O(N) → For stacks and result arrays. 📊 Result: ✔️ 1115 / 1115 test cases passed 📈 Accuracy: 100% An elegant problem blending stack-based range computation with window optimization — a real test of understanding stack fundamentals deeply! 💪 #Day104 #gfg160 #GeeksforGeeks #Java #Stack #SlidingWindow #MonotonicStack #ProblemSolving #DSA #CodingChallenge #LearnByDoing #160DaysOfCode #DailyDSA #SoftwareEngineering #CodingJourney #TechJourney #StJosephsInstituteOfTechnology
To view or add a comment, sign in
-
-
🚀 Day 116 of #gfg160 – 160 Days of Coding Challenges ✅ Problem Solved: Edit Distance (Minimum Operations to Convert s1 → s2) 🔴 Difficulty: Hard 🧠 Approach: To compute the minimum number of operations required to transform one string into another, I used the Dynamic Programming (DP) approach for the classic Edit Distance (Levenshtein Distance) problem. We are allowed 3 operations: ➕ Insert a character ➖ Remove a character 🔁 Replace a character 📌 DP Strategy: 1️⃣ Create a 2D DP table dp[m+1][n+1] • dp[i][j] = minimum operations to convert first i chars of s1 into first j chars of s2 2️⃣ Base cases: • If s1 is empty → need j insertions • If s2 is empty → need i deletions 3️⃣ Transition: If characters match → no new operation dp[i][j] = dp[i-1][j-1] If they don’t match → choose min of • Insert • Delete • Replace dp[i][j] = 1 + min(dp[i][j-1], dp[i-1][j], dp[i-1][j-1]) 4️⃣ Return dp[m][n] → the final edit distance. This method efficiently checks all possibilities while avoiding recomputation using DP. ⚡ Complexity: 🕒 Time Complexity: O(m × n) 💾 Space Complexity: O(m × n) Where m and n are lengths of the two input strings. 📊 Result: ✔️ 1115 / 1115 test cases passed 📈 Accuracy: 100% Edit Distance is one of the most fundamental problems in text processing and DP — and always rewarding to crack! 💪✨ #Day116 #gfg160 #GeeksforGeeks #Java #DynamicProgramming #EditDistance #Levenshtein #ProblemSolving #DSA #CodingChallenge #LearnByDoing #TechJourney #DailyDSA #160DaysOfCode #Consistency #SoftwareEngineering #StJosephsInstituteOfTechnology
To view or add a comment, sign in
-
-
🎯 Day 8 of #365DaysofDSA Today I solved “Convert Sorted Array to Binary Search Tree” (LeetCode #108) 🌲 💡 Concepts used: • Recursion • Divide and Conquer • Binary Search Tree Construction ✨ Approach Summary: The goal is to convert a sorted array into a height-balanced BST. To maintain balance, I picked the middle element of the array as the root — ensuring roughly equal elements on both sides. Then recursively repeated the process for left and right halves of the array. For each recursive call: 1️⃣ Find the middle index of the current subarray. 2️⃣ Create a node with that middle element. 3️⃣ Recursively build left and right subtrees using the respective halves. 🚀 Key takeaway: The divide and conquer strategy naturally fits problems that require balance and recursion — just like in this BST construction. Breaking a big problem into symmetric subproblems leads to elegant and efficient solutions. 🌿 #Day8 #DSA #LeetCode #Java #BinarySearchTree #Recursion #ProblemSolving #CodingJourney #LearnByDoing #Programming
To view or add a comment, sign in
-
-
💡 LeetCode 3467 – Transform Array 💡 Today, I solved LeetCode Problem #3467: Transform Array, which focuses on array manipulation and the use of conditional logic in Java — a neat problem that strengthens core programming fundamentals. ⚙️ 🧩 Problem Overview: You’re given an integer array nums. Your task is to: Replace even numbers with 0 Replace odd numbers with 1 Then, sort the transformed array in ascending order. 👉 Example: Input → nums = [4, 7, 2, 9] Output → [0, 0, 1, 1] 💡 Approach: 1️⃣ Iterate through the array. 2️⃣ Use a ternary operator to transform each element (even → 0, odd → 1). 3️⃣ Sort the array to arrange all zeros before ones. ⚙️ Complexity Analysis: ✅ Time Complexity: O(n log n) — due to sorting. ✅ Space Complexity: O(1) — in-place transformation. ✨ Key Takeaways: Practiced logical thinking and ternary operations in Java. Strengthened understanding of array transformations and sorting. Reinforced the value of writing clean, concise, and efficient code. 🌱 Reflection: Even simple transformation problems like this one sharpen the habit of thinking algorithmically. Consistency in small challenges leads to big growth in problem-solving skills. 🚀 #LeetCode #3467 #Java #ArrayManipulation #LogicBuilding #ProblemSolving #CodingJourney #DSA #CleanCode #ConsistencyIsKey
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