Hello Everyone! After a long time, Sat at LeetCode Biweekly contest 180. Today's contest felt quite easy and I solved first three problems within 20 minutes and attempted the fourth problem 1) Traffic Signal Color(easy): can be solved by writing if else condition, the problem is so much straight forward. 2) Count Digit Appearance(Medium): Used digit extraction for each number in array and stored the digits in map data structure and return the frequency of the given digit Input: nums = [12,54,32,22], digit = 2 map: [1 : 1, 2 : 4, 3 : 1, 4 : 1, 5 : 1] --> Output: 4 3) Minimum Operations to Transform Array into Alternating Prime(Medium): iterated the given nums array twice ,one for even indexes and other for odd indexes. (Odd index must have non prime numbers) In odd index iteration, checked whether a number is prime , if it is prime and the number is 2 , then count will be incremented by 2 or if the number is prime and not 2 , then count will be incremented by 1. (Even index must have prime numbers) In even index iteration, for each number the count will be incremented by 1 until the prime number is reached (used looping and each iteration checks for prime number) Hoping to stay consistent and solve more different and creative problems ☺️ #cpp #competitiveprogramming #leetcode #problemsolving
LeetCode Biweekly Contest 180 Recap: Easy and Medium Problems Solved
More Relevant Posts
-
Ever wondered why LeetCode says "non-decreasing order" instead of just "increasing"? It's not fancy jargon, it's precision. "Increasing" technically means every element is strictly greater than the previous one. So [1, 1, 2, 3] would NOT qualify. "Non-decreasing" means each element is ≥ the previous. So [1, 1, 2, 3] is perfectly valid. In math terms: → Strictly increasing: arr[i] < arr[i+1] → Non-decreasing: arr[i] ≤ arr[i+1] One wrong interpretation and you're filtering out duplicates that should stay and your solution breaks on edge cases. Same logic applies the other way: "Non-increasing" allows duplicates. "Strictly decreasing" doesn't. Tiny word, big difference. Read problem statements carefully. 🙂 #DSA #LeetCode #SoftwareEngineering #CodingTips
To view or add a comment, sign in
-
🔹 Starting LeetCode? These Techniques You Must Know When I started thinking about practicing problems on LeetCode, I realized that solving questions randomly isn’t enough. Understanding key problem-solving techniques is what actually makes a difference. Some important techniques every beginner should know: • Two Pointer • Sliding Window • Prefix Sum • Binary Search Today, I explored one of these techniques 👇 🔸 Two Pointer Technique It involves using two indices to traverse an array or string instead of nested loops. 🔸 When to use it? Sorted arrays Pair-related problems Removing duplicates or reversing 🔸 Why is it important? It helps reduce time complexity from O(n²) to O(n), making solutions more efficient. 🔸 Key Learning Instead of checking every pair, using two pointers makes the approach much smarter and optimized. This is just one technique—more to explore next 🚀 #Leetcode #DSA #CodingJourney #ProblemSolving
To view or add a comment, sign in
-
-
🚀 LeetCode Progress Update: Consistency over Perfection Just solved and submitted “Delete and Earn” (LeetCode 740) — a classic problem that looks tricky at first but becomes elegant once you see the pattern. 🔍 Key Insight This problem reduces to the House Robber pattern: Convert values → points[i] = i * frequency(i) Then apply DP: dp[i] = Math.max(points[i] + dp[i - 2], dp[i - 1]) 💡 What I focused on: Implemented Top-Down (Memoization) Built Bottom-Up (1D DP) Optimized to O(1) space Same problem. Three approaches. One deeper understanding. 📈 Current Progress: ~42% of LeetCode journey Not even halfway — but the focus now is different: ⏱️ Solving under time pressure 🧠 Recognizing patterns faster ✍️ Writing clean, structured code I’m no longer just solving problems — I’m training for real interview scenarios. 🔗 GitHub: https://lnkd.in/gnEfmGAg #LeetCode #Java #DataStructures #Algorithms #DynamicProgramming #CodingInterview #100DaysOfCode
To view or add a comment, sign in
-
-
I just returned false on a LeetCode problem… and it passed ALL 67 test cases. No loops. No base conversions. No palindrome checks. Just one line: return false; And it got accepted instantly. The problem? 2396. Strictly Palindromic Number You had to check if a number n is a palindrome in every base from 2 to n-2. Sounds brutal, right? Then I actually read the problem properly. Here's the mind-blowing part: For any n ≥ 4, when you convert it to base (n-2), it always becomes "12". n=5 → base 3 → "12" n=6 → base 4 → "12" n=10 → base 8 → "12" "12" is never a palindrome. So it's mathematically impossible for any number ≥ 4 to be strictly palindromic. For n=1,2,3 the base range is invalid anyway. The answer is always false. The entire "hard" problem collapses into a single line of code. Lesson for every developer: Before you write clever code, ask yourself: Is this problem even possible? Sometimes the best solution isn’t optimized algorithms. It’s pure elimination. O(1) thinking. Read the problem. Really read it. #LeetCode #ProblemSolving #SoftwareEngineering #Coding #DSA #BackendEngineering #CodingInterview #DeveloperMindset #CleanCode
To view or add a comment, sign in
-
-
🚀 Day 4 of My LeetCode Journey Solved today’s problem: Two Edit Words ✅ Really enjoyed working on this one! 🔹 Problem Statement: Return all words in the dictionary that are exactly two edits away from any of the given queries (edit = insert, delete, or replace a character). 🔹 Approach: • For each query, compared it with every word in the dictionary • Counted character differences • If differences == 2 → valid word • Optimized by breaking early if differences exceed 2 🔹 Complexity: • Time Complexity: O(Q × N × L) • Space Complexity: O(1) 🧠 Key Learning: Handling string problems efficiently by avoiding unnecessary comparisons can significantly improve performance. 📊 Today’s Stats: ✅ Runtime: 0 ms (Beats 100%) ✅ Memory: 12.44 MB Consistency is the real game changer 💪 #LeetCode #DSA #CodingJourney #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 2: Leetcode – 704. Binary Search Today’s problem looked straightforward, but it exposed how small mistakes in control flow can completely break the logic. The Key Insight: Binary search isn’t just about comparing values — it’s about maintaining the correct search space and letting the loop run until it’s fully exhausted. Returning too early can silently ruin the entire algorithm. My Mistake: I placed return -1 inside the loop, which caused the function to exit after just one iteration if the target wasn’t found immediately. The code compiled fine but the logic was wrong — a good reminder that passing compilation doesn’t mean correctness. My Approach: Initialize low = 0 and high = n-1 Calculate mid each iteration Compare nums[mid] with target Adjust search space accordingly Only return -1 after the loop ends Takeaway: Binary search is simple in theory but demands discipline in implementation. One misplaced return or bracket can turn a correct idea into a faulty solution. Day 2 Completed #LeetCode #DSA #BinarySearch #Learning #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 4 of My LeetCode Journey — Building Problem-Solving Muscle Today I worked on two problems: 🔹 Max Consecutive Ones (LeetCode 485) 🔹 Missing Number (LeetCode 268) 💡 Problem 1: Max Consecutive Ones This problem is all about pattern recognition. 👉 Traverse the array 👉 Keep counting consecutive 1s 👉 Reset when you hit 0 Simple logic, but a great reminder that not every problem needs complex data structures. 💡 Problem 2: Missing Number This one was interesting — multiple ways to solve it: ✔️ Sorting ✔️ HashSet ✔️ XOR ✔️ Sum formula (most optimal) The cleanest approach: 👉 Use the formula: n * (n + 1) / 2 👉 Subtract the actual sum 👉 Boom — missing number found ⚡ 🔥 Key Takeaways from Today: Not every problem needs brute force There’s always a more optimal way — look for patterns Understanding multiple approaches = stronger fundamentals Consistency is slowly turning confusion into clarity 💪 On to Day 5 🚀 #LeetCode #DataStructures #Algorithms #CodingJourney #100DaysOfCode #SoftwareEngineering #Programming #InterviewPrep #JavaScript #CodingLife #TechGrowth #ProblemSolving #Developers #LearnToCode #Consistency #CodeNewbie #DailyCoding
To view or add a comment, sign in
-
🚀 LeetCode Daily Challenge 🔗 Problem: https://lnkd.in/gZ52pSZR 💡 My thought process: The solution operates in two separate passes: 1. Left-to-Right Pass: For each element at index "i", calculate the distance to all previous occurrences of that value. If a value has appeared "k" times before, the sum of distances is found using this formula: (count * current_index) - (sum of previous_indices). By storing the count and the running sum of indices in a hash map, we can compute this in constant time. 2. Right-to-Left Pass: The same logic is applied in reverse to calculate the distance from the current index to all future occurrences. In this case, the formula changes to: (sum of future_indices) - (count * current_index). By adding the results from both directions, the code captures the total absolute difference for every identical pair without the performance cost of a nested loop. 👉 My Solution: https://lnkd.in/gfEc7Kis If you found this breakdown helpful, feel free to ⭐ the repo or connect with me on LinkedIn 🙂🚀 #️⃣ #leetcode #cpp #dsa #coding #problemsolving #engineering
To view or add a comment, sign in
-
-
🚀 Day 89 of LeetCode Problem Solving Journey — 100 Days LeetCode Challenge Today, I solved LeetCode #162 — Find Peak Element using C++, under the guidance of Trainer NEKAL SINGH SALARIA Singh at REGex Software Services. 🔍 Problem Summary: Given an integer array nums, find a peak element and return its index. A peak element is greater than its neighbors. 🧠 Approach Used (Binary Search): I used the binary search technique to find a peak efficiently: Initialize low = 0 and high = n - 1 Calculate mid = (low + high) / 2 If nums[mid] < nums[mid + 1] → move to the right half Else → move to the left half (including mid) Continue until low == high At the end, low (or high) will point to a peak element. 📚 Key Learnings of the Day ✔ Binary search can be applied beyond sorted arrays ✔ Comparing adjacent elements helps identify direction ✔ Divide-and-conquer improves efficiency ✔ There can be multiple peaks — return any one ⏱ Complexity • Time Complexity: O(log n) • Space Complexity: O(1) 💡 Optimization Insight: A linear scan would take O(n) time, but binary search reduces it to O(log n), making it optimal for large inputs. Almost at the finish line — see you on Day 90 🚀 #Day89 #100DaysLeetCodeChallenge #LeetCode #RegexSoftwareServices #NekalSingh #ProblemSolving #DSA #CPlusPlus #CodingChallenge #ProgrammingJourney #BinarySearch #KeepGrowing
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
Why do you need two loops for 3rd ques? Can be done in single iteration only