Stack is a linear data structure that follows the LIFO principle (Last In, First Out). Elements are added and removed only from the top of the stack. Stacks are widely used in function calls, undo/redo operations, and backtracking. They play a key role in expression evaluation and syntax checking. Understanding stacks builds a strong foundation for advanced DSA concepts . #python #programming #DSA #SoftwareEngineering
Stack Data Structure: LIFO Principle and Applications
More Relevant Posts
-
LeetCode Problem 1784: "Check if binary string has atmost one segment of ones": Given a binary string s without leading zeros, return true if s contains at most one contiguous segment of ones. Otherwise, return false. Approach: The idea is simple and straightforward, the given string has no leading zeroes, while looping ensure that after encountering the first segment of ones, no 1 is encountered. If this condition holds, then return True else False. The implementation in Python correctly resolves this problem optimally and efficiently. Time Complexity: O(n) where n is length of given string Space Complexity: constant #LeetCode #Python #Strings #DataStructures #Algorithms #OptimalSolution #ProblemSolving #CompetitiveProgramming #DailyCoding #Programming
To view or add a comment, sign in
-
-
LeetCode Problem 1009: "Complement of base 10": The complement of an integer is the integer you get when you flip all the 0's to 1's and all the 1's to 0's in its binary representation. For example, The integer 5 is "101" in binary and its complement is "010" which is the integer 2. Given an integer n, return its complement. Approach: First get the binary string representation of given number using bin() and str() functions, second iterate through the string and append '0' to a new string variable if you get '1' and '1' if you get '0', last return the integer value of the new string variable using the int() function with base 2. #Python #Strings #LeetCode #CompetitiveProgramming #DataStructures #DSA #Algorithms #Programming #ProblemSolving
To view or add a comment, sign in
-
-
📌 NumPy Built-in Methods NumPy provides several built-in functions to quickly create arrays. 🔹 arange() – Creates an array with a range of numbers np.arange(0,10) 🔹 zeros() – Creates an array filled with zeros np.zeros(3) np.zeros((5,5)) → creates a 5×5 matrix of zeros 🔹 ones() – Creates an array filled with ones np.ones(3) np.ones((3,3)) → creates a 3×3 matrix of ones These built-in methods make array creation fast and efficient in NumPy. #Python #NumPy #Programming #DataAnalytics #LearningPython
To view or add a comment, sign in
-
-
✅ Day 3 of #DSAPrep > Problem: Fibonacci Number > Platform: LeetCode > Concept: Recursion + Memoization (Top-Down DP) Used recursion with a dictionary to store previously computed Fibonacci values. This avoids repeated calculations and reduces exponential time complexity to linear time. > Time Complexity: O(n) > Space Complexity: O(n) Understanding how memoization transforms brute-force recursion into efficient dynamic programming. #DataStructures #Algorithms #Python #DynamicProgramming #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
-
LeetCode 232 | Implement Queue using Stacks 🚀 🔹 Data Structure: Stack + Queue Concept 🔹 Idea: Use two stacks to simulate FIFO behavior 🔹 Current Approach: Push O(n), Pop O(1) 🔹 Key Learning: Stack reversal gives queue order Understanding how data structures can simulate each other improves problem-solving depth 💡 #DSA #LeetCode #DataStructures #Stack #Queue #Python #CodingJourney
To view or add a comment, sign in
-
❄️ takeUforward ✅ Symmetric Pattern Problem | Logic Optimization | Python Today I worked on solving a complex symmetric star pattern problem using Python. I spent nearly 1 hour trying to simplify the logic and reduce the number of variables — a great learning experience in problem-solving and pattern recognition. 💡 Problem Approach • Generate a symmetric pattern using nested loops. • Control stars and spaces based on row position. • Handle increasing and decreasing pattern structure. • Focus on writing cleaner and shorter logic. ⏱ Complexity • Time: O(n²) • Space: O(1) 📌 Key Learning Improving logic clarity and reducing unnecessary variables makes code easier to understand and maintain. Struggling with optimization helps build strong problem-solving skills. 🚀 Day 34 completed — improving pattern logic and coding efficiency. #Python #DSA #Programming #ProblemSolving #CodingJourney #LearningInPublic #100DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Day-48 of #100DaysOfCode 🐍 Python Pattern Programming – Continuous Alphabet Triangle Today I implemented an Alphabet Triangle Pattern where characters print continuously using ASCII values. 🔹 Concepts Practiced: ✔ Nested loops ✔ ASCII value manipulation ✔ chr() function ✔ Sequential character logic ✔ Pattern visualization 🔹 Approach: Initialize ASCII value to 65 Convert ASCII to character using chr() Increment the value after each print Continue sequence across rows 🔹 Key Learning: This exercise improved my understanding of character encoding, loop control, and pattern logic building, which are important for strengthening programming fundamentals. #Python #PatternProgramming #AlphabetPattern #CorePython #100DaysOfCode #Day48 #LearnPython #CodingPractice #PythonDeveloper
To view or add a comment, sign in
-
-
Day 5 – DSA Practice | GFG Problem of the Day Continuing my daily DSA consistency with today’s problem. Problem: Union of Arrays with Duplicates The task was to return all distinct elements present in either of the two arrays. At first glance, it looks simple — but handling duplicates efficiently is key when constraints go up to 10⁶ elements. Approach Used: Instead of manually checking duplicates, I used Python’s set data structure, which automatically stores only unique values. Steps: Convert both arrays into sets Perform union operation Return the result as a list Time Complexity: O(n + m) Space Complexity: O(n + m) What I Learned: Choosing the right data structure simplifies the problem Sets are extremely powerful for uniqueness problems Clean code > lengthy logic Always think about constraints before deciding the approach Even “easy” problems strengthen fundamentals #Day5 #DSA #GeeksforGeeks #ProblemOfTheDay #CodingJourney
To view or add a comment, sign in
-
-
✅ Day 49 of 100 Days LeetCode Challenge Problem: 🔹 #1046 – Last Stone Weight 🔗 https://lnkd.in/gAeEMysb Learning Journey: 🔹 Today’s problem focused on repeatedly smashing the two heaviest stones until only one or none remains. 🔹 I used a max-heap approach by storing negative values in Python’s min-heap implementation. 🔹 Each step involved removing the two largest stones, calculating their difference, and pushing the remaining weight back into the heap if needed. 🔹 This ensured efficient retrieval of the heaviest stones at every iteration. Concepts Used: 🔹 Heap / Priority Queue 🔹 Max-Heap Simulation 🔹 Greedy Strategy 🔹 Simulation Key Insight: 🔹 Using negative values is a simple trick to simulate a max-heap using Python’s min-heap. 🔹 Heap structures are ideal when repeatedly accessing extreme values. 🔹 Simulation problems become efficient when paired with the right data structure. #LeetCode #DataStructures #Algorithms #CodingInterview #SoftwareEngineering #SoftwareDeveloper #ProblemSolving #Programming #ComputerScience #TechCareers #100DaysOfCode #DailyCoding #Consistency #LearningInPublic #Python #BackendDevelopment #InterviewPreparation #TechCommunity
To view or add a comment, sign in
-
-
🔹 Problem Statement Given a string s, reverse only the vowels in the string and return the updated string. Vowels include a, e, i, o, u and they may appear in both lowercase and uppercase. 🔹 Example Input: IceCreAm Output: AceCreIm Explanation: The vowels in the string are ['I', 'e', 'e', 'A']. After reversing their order, the string becomes AceCreIm while all consonants remain in their original positions. 📌 Key Concepts Practiced String traversal List operations Stack behavior using pop() Problem decomposition Consistently practicing coding problems helps strengthen logic building and algorithmic thinking. #Python #Programming #DataStructures #ProblemSolving #CodingPractice
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
My favorite real-world application of Stack is Undo / Redo functionality, because it clearly demonstrates how LIFO works in everyday applications.