A collection of Python solutions to HackerRank practice problems, organized by week.
hackerrank/
├── Week1/
│ ├── Flippingbits.py
│ ├── XOR_string2.py
│ ├── birthday_subdivision.py
│ ├── counting_sort.py
│ ├── diagonal_difference.py
│ ├── lonelyInteger.py
│ ├── matchingstrings.py
│ ├── minmaxsum.py
│ ├── pangrams.py
│ ├── plusminus.py
│ ├── timeconversion.py
│ └── twoarrays.py
└── Week2/
├── Countergame.py
├── drawing_book.py
├── lists.py
├── sales_market.py
└── sumXor.py
| File | Description |
|---|---|
Flippingbits.py |
Flips all bits (0↔1) of a 32-bit unsigned integer and returns the decimal value of the result. |
XOR_string2.py |
Computes the XOR of two binary strings, bit by bit. |
birthday_subdivision.py |
Counts the number of ways to choose a contiguous subarray of chocolates that sums to a birthday number d, with exactly m chocolates. |
counting_sort.py |
Implements the counting sort algorithm to sort a list of integers in linear time. |
diagonal_difference.py |
Calculates the absolute difference between the sums of a square matrix's two diagonals. |
lonelyInteger.py |
Finds the one integer in an array that occurs an odd number of times, while all others occur exactly twice. |
matchingstrings.py |
Counts how many times each query string appears in an array of strings. |
minmaxsum.py |
Given five integers, finds the minimum and maximum values from summing four of the five. |
pangrams.py |
Checks whether a given sentence is a pangram (contains every letter of the alphabet at least once). |
plusminus.py |
Calculates the ratio of positive, negative, and zero values in an array. |
timeconversion.py |
Converts a 12-hour AM/PM time format to 24-hour military time format. |
twoarrays.py |
Determines whether two arrays can be paired index-by-index so every sum is ≥ a given value k. |
| File | Description |
|---|---|
Countergame.py |
A counter/game-based problem involving determining a winner based on numeric operations (e.g., reducing a number by its largest power of 2). |
drawing_book.py |
Calculates the minimum number of page turns needed to reach a specific page in a book, turning from either the front or the back. |
lists.py |
Implements a series of Python list operations (insert, remove, append, sort, pop, reverse, print) based on given commands. |
sales_market.py |
Finds items sold in one shop but not in another (symmetric difference type problem). |
sumXor.py |
Counts how many values of x satisfy a + x = a ^ x (sum equals XOR) for a given number a. |
Each script is standalone and can be run directly with Python 3:
python3 Week1/diagonal_difference.pySome scripts read input via input() (as per HackerRank's I/O format), so you may need to provide input either interactively or by piping a file:
python3 Week1/counting_sort.py < input.txt- Python 3.x
- No external dependencies (standard library only, unless a specific script states otherwise)
This repo is a personal archive of solutions written while practicing algorithmic problem solving on HackerRank. Solutions prioritize clarity and correctness over micro-optimization.
This is a personal practice repo, but suggestions and alternative approaches are welcome via issues or pull requests.
Feel free to reference or reuse any solutions here for learning purposes.