This is a submission for the 2025 Hacktoberfest Writing Challenge: Contribution Chronicles
Repository: mah-shamim/leet-code-in-php
π‘ The Idea Behind the Project
As a PHP developer, Iβve often noticed that while most algorithmic problems are solved using Python, Java, or C++, thereβs limited learning material for developers who want to master data structures and algorithms using PHP β especially legacy versions like PHP, which are still used in production by many companies.
That inspired me to create this repository:
π LeetCode in PHP β a collection of optimized PHP solutions to classic LeetCode problems, explained in detail and documented like a tutorial.
Itβs not just about solving problems β itβs about making algorithms accessible to PHP developers who want to strengthen their fundamentals without switching languages.
π§ What I Worked On
During Hacktoberfest 2025, I focused on:
- Structuring the repository for easy navigation (by problem type and difficulty).
- Adding step-by-step explanations for each problem.
- Ensuring compatibility with PHP and CLI execution.
- Improving code readability with clear comments and time complexity notes.
- Writing clean, testable functions with no external dependencies.
Hereβs a quick look at one of the problems I contributed β βLetter Combinations of a Phone Number.β
π§© Example: Letter Combinations of a Phone Number
Problem:
Given a string containing digits from 2-9, return all possible letter combinations that the number could represent.
Solution (PHP):
<?php
function letterCombinations($digits) {
if (empty($digits)) return [];
$map = [
'2' => ['a','b','c'],
'3' => ['d','e','f'],
'4' => ['g','h','i'],
'5' => ['j','k','l'],
'6' => ['m','n','o'],
'7' => ['p','q','r','s'],
'8' => ['t','u','v'],
'9' => ['w','x','y','z']
];
$result = [''];
foreach (str_split($digits) as $digit) {
$temp = [];
foreach ($result as $combination) {
foreach ($map[$digit] as $char) {
$temp[] = $combination . $char;
}
}
$result = $temp;
}
return $result;
}
// Example
print_r(letterCombinations("23"));
Output:
Array
(
[0] => ad
[1] => ae
[2] => af
[3] => bd
[4] => be
[5] => bf
[6] => cd
[7] => ce
[8] => cf
)
π What Iβm Proud Of
β
Making algorithmic problem-solving approachable for PHP developers.
β
Using legacy PHP to prove that logic, not language, defines efficiency.
β
Writing tutorial-style explanations for every contributor or learner to follow easily.
β
Encouraging contributions from others to solve new problems or optimize existing ones.
π§ What I Learned
- How to refactor recursive and backtracking algorithms for PHPβs older runtime.
- The importance of code readability and documentation in open source.
- How community contributions can improve both code quality and motivation.
- That open-source collaboration is less about competition, and more about collective learning.
π§ Challenges I Overcame
- Balancing backward compatibility with performance optimization.
- Refactoring modern PHP features (like generators or anonymous functions) into PHP equivalents.
- Managing array-based recursion without built-in advanced helpers.
- Writing problems in a consistent structure:
Problem β Approach β Code β Complexity β Example Output.
π€ How to Contribute
You can help make this repository even better!
πΉ Fork the repo
πΉ Solve a new LeetCode problem in PHP
πΉ Follow the naming and documentation format
πΉ Submit a pull request π
π Repo: github.com/mah-shamim/leet-code-in-php
π Final Thoughts
Hacktoberfest 2025 reminded me that sharing knowledge is as valuable as writing code.
Through this project, I hope to inspire more PHP developers to dive into algorithms, contribute confidently to open source, and keep learning β no matter what version of PHP they use!
βCode is temporary, learning is permanent.β π»
Tags: #hacktoberfest #php #opensource #leetcode #programming #tutorial
Top comments (0)