🌿Day 73 LeetCode: Next Greater Element I (496) Approach: Used a stack to find the next greater element for each number in nums2 and stored results in a hash map for quick lookup in nums1. ✨ Learned how to use monotonic stacks for next-greater problems — a smart way to reduce time complexity and strengthen logic! 📈 Improved understanding of stacks, hash maps, and element mapping techniques in C++. #LeetCode #100DaysOfCode #DSA #Stack #HashMap #Arrays #ProblemSolving #CodingJourney #CodeEveryday
Solved LeetCode 496 with stack and hash map in C++
More Relevant Posts
-
✨Day 67 LeetCode: Letter Combinations of a Phone Number (17) Approach: Used backtracking to generate all possible letter combinations mapped from digits, following the classic phone keypad pattern. ✨ Learned how recursion and backtracking can explore all possible paths efficiently — a great exercise in mapping and combinatorial logic! 📈 Improved understanding of recursion, string building, and backtracking patterns in C++. #LeetCode #100DaysOfCode #DSA #Backtracking #Strings #ProblemSolving #CodingJourney #CodeEveryday
To view or add a comment, sign in
-
-
Day 105 of 365 of Solving LeetCode Problems! ✅ Generate All Binary Strings: Given an integer n, generate all binary strings of length n representing bits. Return the strings in ascending order. Key Observations: 1) This is a classic recursion and backtracking problem — each position can either be '0' or '1'. 2) You explore both possibilities recursively until the string reaches length n. 3) The order of recursive calls ('0' first, then '1') ensures the results are in lexicographical (ascending) order. 4) Time complexity is O(2^n) since there are 2^n possible binary strings. #Recursion #Backtracking #LeetCode #DSA
To view or add a comment, sign in
-
-
Day 22 of #100DaysOfCode Today I solved the “Permutation in String” problem on LeetCode — a tricky one that really sharpens your understanding of sliding window and frequency mapping in strings. 🧩 Problem in short: Given two strings s1 and s2, the task is to check if any permutation of s1 exists as a substring in s2. At first glance, it feels like a brute-force problem — generate all permutations of s1 and check each in s2. But that’s computational suicide for longer strings. So the challenge was to find a smarter, optimized approach. ⚙️ Intuitive Approach: Instead of generating permutations, I focused on character frequencies. Maintain two frequency arrays — one for s1 and one for the current window of s2. Slide the window across s2, adding and removing characters as you move. Whenever both frequency arrays match, it means that substring of s2 is a permutation of s1. This approach reduces the complexity drastically and relies on pattern recognition through frequency matching, not brute force. Every day in this challenge is a reminder that optimization isn’t about doing less work — it’s about doing the right work. #LeetCode #C++ #ProblemSolving #DSA #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🌿Day 52 LeetCode: Valid Sudoku (36) Approach: Used hash sets to track numbers appearing in each row, column, and 3×3 sub-box while validating the board. ✨ Learned how to handle 2D grids efficiently and apply set-based validation for constraints checking! 📈 Strengthened logical reasoning and improved understanding of hash sets and matrix traversal in C++. #LeetCode #100DaysOfCode #DSA #HashSet #Matrix #ProblemSolving #CodingJourney #LogicBuilding
To view or add a comment, sign in
-
-
🌿Day 55 LeetCode: Daily Temperatures (739) Approach: Used a stack to keep track of indices of unresolved temperatures. Traversed the array and calculated the number of days until a warmer temperature efficiently. ✨ Learned how to use monotonic stacks for next-greater-element problems — a great exercise in optimizing brute-force solutions! 📈 Improved understanding of stacks, array traversal, and problem-solving patterns in C++. #LeetCode #100DaysOfCode #DSA #Arrays #Stack #ProblemSolving #CodingJourney #CodeEveryday
To view or add a comment, sign in
-
-
🚀 Day 112 of #LeetCode Challenge! Problem: Diameter of Binary Tree 💡 My Approach: The diameter of a binary tree is the longest path between any two nodes (may or may not pass through the root). The trick is to calculate the height of each subtree while keeping track of the maximum left + right path encountered. Use a helper function height() that: Recursively computes left and right subtree heights. Updates the global diameter as the maximum sum of left and right heights. ✨ Example: Input: [1,2,3,4,5] Output: 3 Explanation: The longest path is [4,2,1,3] or [5,2,1,3] ⏱ Time Complexity: O(N) — visit every node once 💾 Space Complexity: O(H) — recursive stack (H = height of tree) 🌱 Key Insight: At each node, the longest path through it is leftHeight + rightHeight. The overall diameter is the maximum of all such paths. 👨💻 GitHub Link: https://lnkd.in/dvUDMZUC #LeetCode #BinaryTree #Recursion #TreeTraversal #DSA #CodingChallenge #C++ #Day112
To view or add a comment, sign in
-
-
🚀 Day 115 of #LeetCode Challenge! Problem: Symmetric Tree 🌳 Concept: Check whether a binary tree is a mirror of itself (i.e., symmetric around its center). 💡 My Approach: Use recursion to compare left and right subtrees. A tree is symmetric if: Left subtree of left node matches right subtree of right node Right subtree of left node matches left subtree of right node Base cases: Both nodes NULL → symmetric ✅ One NULL and one not → not symmetric ❌ Values must match ✨ Example: Input: [1,2,2,3,4,4,3] Output: true ⏱ Time Complexity: O(N) — visiting all nodes 📦 Space Complexity: O(H) — recursion stack (H = height of tree) 📌 Key Insight: This is a classic mirror check — left's left must mirror right's right! 👨💻 GitHub Link: https://lnkd.in/gid6xjvn #LeetCode #BinaryTree #Recursion #SymmetricTree #MirrorTree #DSA #ProblemSolving #C++ #CodingChallenge #Day114
To view or add a comment, sign in
-
-
🚀 Day 114 of #LeetCode Challenge! Problem: Symmetric Tree 🌳 Concept: Check whether a binary tree is a mirror of itself (i.e., symmetric around its center). 💡 My Approach: Use recursion to compare left and right subtrees. A tree is symmetric if: Left subtree of left node matches right subtree of right node Right subtree of left node matches left subtree of right node Base cases: Both nodes NULL → symmetric ✅ One NULL and one not → not symmetric ❌ Values must match ✨ Example: Input: [1,2,2,3,4,4,3] Output: true ⏱ Time Complexity: O(N) — visiting all nodes 📦 Space Complexity: O(H) — recursion stack (H = height of tree) 📌 Key Insight: This is a classic mirror check — left's left must mirror right's right! 👨💻 GitHub Link: https://lnkd.in/grXFRA2i #LeetCode #BinaryTree #Recursion #SymmetricTree #MirrorTree #DSA #ProblemSolving #C++ #CodingChallenge #Day114
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