A collection of Python solutions for various HackerRank programming challenges, covering fundamental algorithms, data structures, and Python-specific concepts.
# Run any solution
python <filename>.py
# Run tests (where available)
python test_<filename>.py- py-collections-deque.py - Double-ended queue operations
- py-collections-namedtuple.py - Named tuple usage
- py-collections-ordereddict.py - Ordered dictionary implementation
- py-set-add.py - Adding elements to sets
- py-set-difference-operation.py - Set difference operations
- py-set-discard-remove-pop.py - Set element removal methods
- py-set-intersection-operation.py - Set intersection operations
- py-set-mutations.py - Set mutation operations
- py-set-symmetric-difference-operation.py - Symmetric difference operations
- py-set-union.py - Set union operations
- py-ginorts.py - Custom string sorting with specific rules
- py-word-order.py - Word ordering and frequency analysis
- py-most-commons.py - Finding most common characters
- python-arithmetic-operators.py - Basic arithmetic operations
- python-division.py - Division operations
- python-loops.py - Loop constructs
- python-print.py - Print statement variations
- write-a-function.py - Function definition and leap year logic
- py-if-else.py - Conditional logic
- py-piling-up.py - Stack-based problem solving
- py-the-captains-room.py - Finding unique elements
Some solutions include comprehensive unit tests:
- test_py_ginorts.py - Complete test suite for the ginorts string sorting problem
Tests cover:
- Basic functionality
- Edge cases (empty inputs, single characters)
- Error handling
- Performance with large inputs
- Each file is a standalone solution
- Input/output handled via
input()andprint() - Main execution in
if __name__ == '__main__':blocks - Modular functions for complex problems
- Uses Python's built-in
unittestmodule - Comprehensive test coverage including edge cases
- Performance testing for larger inputs
Implements custom sorting with specific rules:
- Lowercase letters (alphabetically)
- Uppercase letters (alphabetically)
- Odd digits (numerically)
- Even digits (numerically)
Demonstrates proper usage of Python's collections module:
dequefor efficient append/pop operationsCounterfor frequency analysisOrderedDictfor maintaining insertion order
- Input Processing - Robust input handling and validation
- Algorithm Implementation - Clean, readable solution logic
- Edge Case Handling - Comprehensive coverage of boundary conditions
- Testing - Unit tests where complexity warrants verification
- Python 3.x
- No external dependencies (uses standard library only)
These solutions demonstrate key Python concepts:
- Lambda functions and custom sorting
- Collections module usage
- String manipulation techniques
- Set operations and mathematical concepts
- Error handling and input validation