LeetCode 347: Top K Frequent Elements ✅ This one tested more than syntax — it tested patience. At first, broke the problem apart, and brought out every weapon I had: 1. HashMap for frequency counting 2. Array transformation for sorting 3. Clean extraction of the top-K results The key idea: Count frequency of each element using a map Convert the map into an array Sort by frequency in descending order Pick the top K elements ⏱ Time Complexity: O(n log n) — sorting the frequency array 🧠 Space Complexity: O(n) — storing frequencies and intermediate arrays 🧠 This problem reinforced something important for me: Feeling stuck doesn’t mean you’re failing — it means you’re learning. #LeetCode #DSA #JavaScript #ProblemSolving #Consistency #NeverGiveUp #LearnInPublic
LeetCode 347: Top K Frequent Elements
More Relevant Posts
-
LeetCode Problem 8: String to Integer (atoi) What I Learned: • How to parse a string step by step instead of directly converting it • The importance of skipping leading whitespaces before processing • How to determine sign (+ / -) safely • Building a number using base-10 math (result = result * 10 + digit) • Why reading must stop at the first non-digit character • Handling 32-bit integer overflow proactively instead of fixing it later Problem Summary: You’re given a string and need to convert it into a 32-bit signed integer by simulating how humans read numbers from text. If the value goes outside the valid range, clamp it to the nearest boundary. #100DaysOfLeetCode #leetcode #javascript #problemsolving #codingjourney #DSA #StringParsing #OverflowHandling Link: https://lnkd.in/gjegrCgU
To view or add a comment, sign in
-
-
From Sorted Data to Balanced Trees: Divide, Conquer, Balance 🌳 Solved LeetCode 108 - Convert Sorted Array to Binary Search Tree today. The solution clicked by treating the array like a search space: -Pick the middle element as the root -Recursively build the left half and right half -Stop when the range becomes invalid This guarantees a height-balanced BST without extra work. Key takeaway: Balanced trees are a natural outcome of divide-and-conquer. Choosing the midpoint at every step keeps depth under control. Strengthening recursive thinking and tree intuition. #LeetCode #DSA #BinarySearchTree #Recursion #DivideAndConquer #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
Fixing an Unbalanced Tree the Systematic Way 🌳 Solved LeetCode 1382 - Balance a Binary Search Tree today. The approach was clean and systematic: -Use inorder traversal to extract nodes in sorted order -Pick the middle element as the root -Recursively build left and right subtrees This guarantees a height-balanced BST without complex rotations. Key takeaway: Sometimes the best way to fix a structure is to rebuild it with the right invariants, not patch it incrementally. This problem nicely connected traversal, sorting, and divide-and-conquer thinking. #LeetCode #DSA #BinarySearchTree #TreeTraversal #DivideAndConquer #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
When One Path Isn’t Enough: Tracking All Valid Paths 🌳 Solved LeetCode 113 - Path Sum II today. Unlike Path Sum I, this version requires returning all root-to-leaf paths that match the target sum. The key shift: -Use recursion to explore paths -Maintain a current path array -Apply backtracking (push before recursion, pop after) Key takeaway: Whenever a problem asks for all combinations or all paths, think backtracking + state cleanup. This one strengthened my understanding of recursion with state management. #LeetCode #DSA #BinaryTree #Backtracking #Recursion #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
📌 #45 DailyLeetCodeDose Today's problem: 141. Linked List Cycle – 🟢 Easy There are two ways to solve such tasks 1. Mark visited nodes, ex. by putting them into hash map 2. More clever way to avoid using extra space – 🦍 Floyd’s Cycle Finding Algorithm The main idea of this algorithm is to use 2 pointers at the same time: slow and fast. Slow goes by 1 step, fast by 2 on each cycle iteration. If two pointers on the same list node, we found a cycle! If you want to read more about it, here is the link: https://lnkd.in/ex25Eyvc Link to the leetcode promlem: https://lnkd.in/eM8KTdy2 #DailyLeetCodeDose #LeetCode #JavaScript #Algorithms #ProblemSolving #Coding
To view or add a comment, sign in
-
-
Seeing Trees Level by Level: Thinking in Breadth 🌳 Solved LeetCode 102 - Binary Tree Level Order Traversal today. Instead of going deep first, this problem flips the mindset to breadth-first traversal, processing nodes level by level using a queue. Each iteration captures all nodes at the current depth before moving deeper. Key takeaway: Tree problems aren’t only about DFS. When the question asks for levels, layers, or distance, BFS is the natural fit. This helped strengthen my intuition on choosing the right traversal based on the problem’s demand. #LeetCode #DSA #BinaryTree #BFS #TreeTraversal #JavaScript #ProblemSolving #LearnInPublic
To view or add a comment, sign in
-
Finding Boundaries, Not Just Targets 🔎 Solved LeetCode 34 - Find First and Last Position of Element in Sorted Array using the lower bound and upper bound approach. Instead of searching for the target once, I ran binary search twice: -First to find the leftmost occurrence -Second to find the rightmost occurrence Key takeaway: Binary Search is not just for finding values. It’s powerful for finding boundaries in sorted data. Thinking in terms of lower and upper bounds turns range problems into clean logarithmic solutions. #LeetCode #DSA #BinarySearch #JavaScript #Algorithms #ProblemSolving #LearnInPublic #DeveloperJourney
To view or add a comment, sign in
-
LeetCode: Longest Consecutive Sequence ✅ This problem real challenge is beating the naïve sorting approach. Strategy: Instead of sorting, I used a HashSet for constant-time lookups. The key idea is to only start counting a sequence when the current number does not have a predecessor (num - 1). From there, expand forward to count the full streak. This ensures every number is visited only once. 🕒 Time Complexity: O(n) — each element is processed at most once 📦Space Complexity: O(n) — extra space for the set 👉 The right data structure often matters more than clever loops. #LeetCode #DSA #JavaScript #ProblemSolving #LearnInPublic #CodingJourney #CSwithDev
To view or add a comment, sign in
-
-
LeetCode 739 – Daily Temperatures (Medium) Solved this problem using a monotonic stack approach. The idea is straightforward: • Traverse from right to left • Maintain a stack of indices with strictly higher temperatures • For each day, calculate how many days ahead a warmer temperature appears This reduces the brute-force approach and keeps the solution efficient at O(n) time complexity. I’m focusing on writing solutions that are easy to understand, not just ones that pass test cases. Code snippet attached 👇 #LeetCode #DSA #JavaScript #Stacks #ProblemSolving #Consistency
To view or add a comment, sign in
-
-
Day 51/100 – Consistency > Motivation Today I explored JavaScript Math Methods and how to convert numbers into integers using different approaches. Here’s what I learned: Math.round(x) – Rounds to the nearest integer Math.ceil(x) – Rounds up to the nearest integer Math.floor(x) – Rounds down to the nearest integer Math.trunc(x) – Returns the integer part of a number It’s interesting how small built-in methods can make a big difference in handling real-world data and calculations. Halfway through this journey, one thing is clear: Consistency builds confidence. No matter how small the topic seems, every day adds up. #100DaysOfCode #Day51 #JavaScript #WebDevelopment #LearningInPublic #Consistency
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
Nice work