Skip to content

Conversation

@saishmungase
Copy link

Description

This PR adds an implementation of a LIFO Stack that supports an additional get_min() operation in O(1) time complexity, as requested in the data_structures README (Medium Priority).

  • File Added: Python/data_structures/stack/stack_with_min.py
  • Functionality: Implements standard stack operations (push, pop, top, is_empty, size) plus get_min() using an auxiliary stack to track minimums.
  • Follows LIFO principle.

Algorithm Description (Included in code comments)

Uses a main stack for elements and an auxiliary stack (_min_stack). When pushing, if the new item is <= the top of _min_stack, it's pushed onto _min_stack. When popping, if the popped item matches the top of _min_stack, it's popped from _min_stack too. get_min() simply returns the top of _min_stack.

Complexity Analysis (Included in code comments)

  • Time Complexity:
    • Push: O(1)
    • Pop: O(1)
    • Top: O(1)
    • GetMin: O(1)
  • Space Complexity: O(n)

Checklist

  • Code follows the project's contributing guidelines (folder structure, naming).
  • Code includes data structure description comment.
  • Code includes time and space complexity analysis.
  • Code is tested (includes doctests).
  • Commit message follows the specified format.
  • This PR adds one specific data structure implementation.

…on list- Time Complexity: Enqueue O(1) avg, Dequeue O(n)- Space Complexity: O(n)
…stacks- Time Complexity: Enqueue O(1), Dequeue O(1) amortized- Space Complexity: O(n)
…) get_min operation- Time Complexity: Push O(1), Pop O(1), Top O(1), GetMin O(1)- Space Complexity: O(n)
@github-actions
Copy link

🎉 Welcome to Hacktoberfest 2025, @saishmungase! 🎃

Thank you for your first contribution to our DSA repository! Here's what happens next:

🔍 Automatic Checks

  • Code Validation: Passed
  • 🧪 Compilation Tests: Passed

📋 Next Steps

🎯 Great job! Your code compiled successfully. Maintainers @Karanjot786 and @Pradeepsingh61 will review your PR soon.

🎁 What You Get

  • 🏆 Hacktoberfest Credit: This PR counts toward your 6 PR goal for exclusive T-shirt + Tree!
  • 🌟 Hall of Fame: You'll be featured in our contributors list
  • 📚 Learning: Code review feedback from experienced developers

💡 Tips for Success

  • Follow our Contributing Guidelines
  • Add comments explaining your algorithm
  • Include time/space complexity analysis
  • Test your code before submitting

Welcome to the community! 🚀

@github-actions
Copy link

🤖 Automated PR Status

🔍 Code Validation

Passed - File naming and structure look good!

🧪 Compilation Tests

Passed - All code compiles successfully!

📋 Overall Status

🎉 Ready for Review - Your PR has passed all automated checks!
👥 Maintainers have been notified for review.


This comment was generated automatically. Checks will re-run when you push new commits.

@github-actions github-actions bot requested a review from Karanjot786 October 27, 2025 15:39
@saishmungase
Copy link
Author

Hey @Pradeepsingh61 , @Karanjot786 Can You Please check this PR ?

@saishmungase saishmungase closed this by deleting the head repository Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant