Day 39 / 100 – Implement Queue using Stacks => Designing a queue (FIFO) behavior using two stacks (LIFO). Time Complexity: Push: O(n) Pop: O(1) Peek: O(1) => Strategy used: Use one primary stack to maintain queue order Use a helper stack during push to reverse elements Always keep the front of the queue on top of the primary stack #LearningInsight This problem reinforces how data structures can be transformed into one another using controlled operations. By carefully managing stack order, we can achieve queue behavior while keeping pop and peek efficient. Strong fundamentals make complex systems easier to reason about. Code pushed to Git https://lnkd.in/gNunRSqn #100DaysOfCode #Python #DSA #Queue #Stack #LeetCode #CodingJourney #ProblemSolving
Implementing Queue using Stacks with O(1) Pop
More Relevant Posts
-
Day 7 of 365 Days of code 🤌 Qn 1):Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. Return true if there is a cycle in the linked list. Otherwise, return false. Explanation: Use two different pointers, one is going to be a slow pointer and another one will be a fast pointer that moves twice the number of nodes of the slow pointer in a single iteration. If both the pointers meet at a same node, then the linked list consists of a cycle. #365daysOfCode #NeetCode #leetcode #DSA #python #LeetCode #ProblemSolving #Algorithms #365dayschallenge
To view or add a comment, sign in
-
-
Day 12/100 – #100DaysOfLeetCode 🚀 🧩 Problem: LeetCode 169 – Majority Element (Easy) 🧠 Approach: Use a hash map to count the frequency of each number. The element that appears more than n/2 times is the majority element. 💻 Solution: class Solution: def majorityElement(self, nums: List[int]) -> int: d = {} for i in nums: d[i]=d.get(i,0)+1 for i in d: if d[i] > len(nums)/2: return i ⏱ Time | Space: O(n) | O(n) 📌 Key Takeaway: Whenever a problem involves counting occurrences, using a hash map is a clean and reliable solution. #leetcode #dsa #python #problemSolving
To view or add a comment, sign in
-
-
Problem: Print Elements of a Linked List Concepts: Linked List Traversal | Pointers | Iteration Difficulty: Easy Problem Summary: Given the head of a singly linked list, traverse the list and print the data of each node line by line. If the head is NULL, nothing should be printed. This problem focuses on understanding how to move through nodes using pointers and access data stored in each node. Key Learnings: A linked list is traversed using a temporary pointer that starts at the head Each node stores both data and a next pointer Traversal continues until the pointer becomes NULL Proper pointer movement is essential to avoid infinite loops GitHub Link:https://lnkd.in/dfxDCKdq #Day40 #DSA #LinkedList #ProblemSolving #DataStructures #Coding #Python #Cplusplus #LearningInPublic #50DaysChallenge #TechJourney
To view or add a comment, sign in
-
-
Day 51 of #100DaysOfLeetCode Today’s problem pushed the difficulty up a notch and marked a deeper dive into dynamic programming with constraints across multiple strings. This was not just about sorting anymore — it was about choosing the right columns to keep so that every row becomes lexicographically sorted. 🧩 Delete Columns to Make Sorted III The task was to remove the minimum number of columns such that each individual string remains sorted from left to right after deletion. This transforms the problem into finding the longest valid sequence of columns that preserves sorted order across all rows. 🧠 My Approach Treated each column as a position in a sequence. Used DP, where dp[i] represents the longest valid sequence ending at column i. For every pair of columns (j, i) with j < i, checked: If all rows satisfy row[j] ≤ row[i]. If valid, updated: dp[i] = max(dp[i], dp[j] + 1) Final answer = total columns − max(dp). This reframes the problem as a Longest Non-Decreasing Subsequence across columns. 💡 What I Learned This challenge highlights how: A hard problem can reduce to a classic DP pattern Thinking in terms of what to keep instead of what to delete simplifies reasoning Constraints across multiple dimensions demand careful validation 📊 Complexity Analysis Time Complexity: O(n² · m) (n = number of columns, m = number of strings) Space Complexity: O(n) ✅ Day 51 Summary A solid DP-heavy problem that reinforces column-wise thinking and optimization. The second half of the journey has officially begun — with harder problems and sharper reasoning ahead. #100DaysOfLeetCode #Day51 #LeetCode #Python #DynamicProgramming #DSA #ProblemSolving #CodingJourney #Consistency #AdityaCodes
To view or add a comment, sign in
-
-
Daily Leetcode Progress | Day 6 ✅ Leetcode 2154 : Keep Multiplying Found Values by Two . . Approach (Hint): I used for _ in range(len(nums)) instead of for i in list Example : for _ in range(len(nums)): ✅ - Only execute length of nums .If original value present keep double its value.If original value is not present break the loop and return original value. for i in list : ❌ - If the original value present in different order it wont work because,for loop not iterating from the start every time (or) original value not in the list it will keep checking to the end of the list .It leads to Time Limit Error. Time Complexity: O(n²) Space Complexity: O(1) #leetcode #dsa #dsa_in_python #leetcode_problem #problem_solving #python
To view or add a comment, sign in
-
-
Solved LeetCode 944 – Delete Columns to Make Sorted 🧠📊 This problem looks simple at first, but it’s a great reminder that clear thinking beats complex logic. 🔍 Problem in short: - You’re given multiple strings of equal length. Imagine them stacked one below another, forming a grid. Your task is to delete columns that are NOT lexicographically sorted from top to bottom and return how many such columns exist. 🧠 How I approached it: 1️⃣ First, I visualized the strings as a table where: - Each row is a string - Each column contains characters from all strings at that position 2️⃣ Then, I checked each column independently: - Start from the top row - Compare every character with the one directly below it 3️⃣ If at any point: - The upper character is greater than the one below → That column is not sorted 4️⃣ The moment a column fails this condition: - I mark it for deletion - Move on to the next column (no need to check further for that one) 5️⃣ Finally, I count how many columns were marked for deletion. ✨ Key takeaway - You don’t always need advanced data structures. - Sometimes, a simple comparison + clean iteration is all it takes. #LeetCode #DSA #ProblemSolving #Python #LearningInPublic #Consistency
To view or add a comment, sign in
-
-
Maintaining an open source project with pure Python for maximized portability, I created a tool to filter dependencies for native/compiled code. This client-side utility includes tree visualization, binary detection, deep scan, and aims at locating potential issues for WASM environments. Prototype with Claude/Gemini, iterations for resolving edge cases, and contributions for improving dependency resolution are welcome. Visualize Python dependencies and subprocess calls in a browser: https://lnkd.in/e7Cv8xaB source,#webassembly,#dependency visualization
To view or add a comment, sign in
-
✨ Day 68 of #100DaysOfDSAChallenge 📌 LeetCode 66: Plus One A simple-looking problem that reinforces the importance of edge-case handling and digit manipulation. 🧩 Problem Overview: Given a large number represented as an array of digits, increment it by one without converting it into an integer. 🧠 Approach & How It Works: Traverse the array from right to left (least significant digit first) If the digit is less than 9, increment and return immediately If the digit is 9, convert it to 0 and propagate the carry If all digits are 9, prepend 1 to the array This ensures an in-place, efficient solution without extra conversions. ⚙️ Performance: 🚀 Runtime: 0 ms (beats 100%) 📦 Memory: 12.35 MB (beats 81.81%) ✅ Testcases Passed: 112 / 112 📘 What I Learned: ✔ Handling carry propagation cleanly ✔ Importance of scanning from the least significant digit ✔ Avoiding unnecessary data type conversions ✔ Writing concise and optimal logic Onward with consistency and problem-solving 💪 #LeetCode #DSAChallenge #PlusOne #Consistency #100DaysOfDSA #100DaysOfCode #ArrayProblems #Python #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
Stop editing old code to add new features. 🛑 The Open/Closed Principle (the 'O' in SOLID) is the secret to a stress-free codebase. The goal: Open for extension, but closed for modification. In Python, we achieve this by using Abstract Base Classes (ABCs). Instead of a giant if-else block that breaks every time you add a new type, you define a blueprint. Why this wins: Zero Regressions: You don't touch the original, tested logic. Easy Scaling: Need a new feature? Just create a new class. Clean Code: Your core logic stays slim and readable. If you’re constantly "opening" old files to add new logic, it’s time to refactor! 🚀 #Python #CleanCode #SoftwareArchitecture #CodingTips
To view or add a comment, sign in
-
One tool to rule them all. Between pip, venv, pyenv, and poetry, Python environment management can feel like juggling too many rings of power. Enter uv, one tool that replaces them all. Create a project, add dependencies, run code, uv handles the virtual environment automatically. No more "which Python am I using?" confusion. And it's 10-100x faster than pip. The real magic? uvx runs tools in isolated, cached environments, no global installation needed. ⚠️ Running code from the internet means trusting the source. Verify package names and repo URLs. More at uv docs: https://cs.co/60467hxls #CiscoDevNet #DevTip #Python #NetworkAutomation #DevOps
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