shlogg · Early preview
Md Ariful Haque @mah-shamim

I am a Technical Lead with holistic knowledge of software development and design. I am also experienced in coordinating with stakeholders

Fraction Addition And Subtraction In PHP

Add fractions with PHP: parse input string, compute result step by step, simplify final fraction. gcd function & addFractions function used for simplification.

Number Complement In Binary Representation

Flip bits of binary representation to find complement: convert num to bin, flip 0s & 1s, then back to int. Example: num=5 -> "101" -> "010" -> 2

Strange Printer In Minimum Turns

Strange Printer problem: use dynamic programming to find min turns to print string s. Initialize dp[i][i] = 1, then fill table with same or different char logic. Result: dp[0][$n - 1]. Efficiently calculates min turns.

Palindrome Partitioning In PHP: All Possible Palindrome Partitions

Partitioning a string into palindromes: [["a","a","b"],["aa","b"]]. Use backtracking & dynamic programming to explore all possible partitions, checking each for being a palindrome.

Maximum Points With Cost In Matrix

Maximize points by picking cells in each row while minimizing cost of switching between rows using dynamic programming and auxiliary arrays left and right.

Summing Root-to-Leaf Numbers In Binary Tree

Sum Root to Leaf Numbers: Use DFS to traverse binary tree & calculate sum of root-to-leaf numbers. Example inputs: [1,2,3] & [4,9,0,5,1]. Output: 25 & 1026 respectively.

Maximal Rectangle Area In Binary Matrix

Maximal Rectangle problem: find largest rectangle containing only 1's in binary matrix. Use dynamic programming & stack-based approach to calculate maximal area.

Binary Search For Kth Smallest Pair Distance In PHP

Find K-th Smallest Pair Distance: Sort nums, use binary search & two-pointer technique. Count pairs with distance ≤ mid, adjust search range. Time complexity: O(n log(max(nums) - min(nums)) + n log n)

Magic Squares In Grid: Counting 3x3 Contiguous Magic Square Subgrids

Counting Magic Squares In Grid: Given a grid of integers, find how many 3x3 contiguous magic square subgrids are there. A magic square has rows, columns & diagonals summing to same value with distinct numbers from 1 to 9.

Sort Colors In One Pass With Constant Extra Space

Sort Colors: Use Dutch National Flag algorithm with constant extra space. Initialize low, mid, high pointers. Swap nums[mid] with nums[low] if 0, move mid if 1, swap with nums[high] if 2. Continue until mid > high.

Spiral Matrix III: Visiting Grid Positions In Clockwise Spiral Order

Walk clockwise spiral through grid (rStart, cStart) visiting every position. Use direction array & step count to manage movement. Add positions to result if within grid boundaries.

Integer To English Words Converter

Convert non-negative integer num to English words representation using recursion & helper function. Handle edge cases like 0 & numbers with intermediate chunks as zero.

Kth Distinct String In Array: Return Kth Unique String

Find kth distinct string in array: create frequency map, collect strings with count 1, return k-th one if exists, else empty string. PHP solution provided.

Range Sum Of Sorted Subarray Sums Modulo 109 + 7

Given array nums, compute sum of all non-empty continuous subarrays, sort them, and return sum from index left to right (1-based) modulo 10^9 + 7.

Senior Citizens Over 60 Years Old Count

Count Senior Citizens: Extract age from details array, convert to int, check if > 60. Loop through each detail, increment counter for seniors. Return count.

Make Two Arrays Equal By Reversing Subarrays

Two arrays can be equal by reversing subarrays if they have same elements with same frequency. Sorting and comparing them is an easy way to achieve this.

Building A Comprehensive Contact Form With PHP And MySQL

Comprehensive contact form app built with PHP, jQuery, AJAX & MySQL, storing details in a relational database and sending email notifications upon submission.

Filling Bookcase Shelves With Min Height

Minimize bookshelf height by placing books with total thickness <= shelfWidth on each level. Use dynamic programming to track min height after placing each book.

Median Of Two Sorted Arrays In O(log(m+n)) Time Complexity

Find median of two sorted arrays nums1 & nums2 with O(log(m+n)) time complexity. Partition smaller array (nums1) using binary search, adjust range based on comparisons, and calculate median from max left & min right elements.

Longest Substring Without Repeating Characters In PHP

Find longest substring without repeating chars: use sliding window & hash map to track char indices. Time complexity O(n). Example usage in PHP.

Software Engineering And Web Development Challenges

Solve graph problem with traffic signals: find second minimum time to reach destination from vertex 1 to n in a bi-directional connected graph.

Software Engineering: Adding Two Numbers As Linked Lists

Add two numbers represented as linked lists: create dummy head node, traverse input lists with pointers, calculate sum and carry, build new linked list with result.

Software Engineering And Web Development Solutions

Implementing Floyd-Warshall's algorithm to find shortest paths between all pairs of cities and then calculating reachable cities within distanceThreshold.

Sort People By Height In Descending Order

Sort people by height: Combine names & heights, sort by height desc, extract sorted names. PHP example: usort($combined, function($a, $b) { return $b[1] - $a[1]; });

Find Valid Matrix Given Row And Column Sums

Find any matrix that satisfies row & column sums: Initialize empty matrix with zeros, iterate over placing min(rowSum[i], colSum[j]) at each position, update sums until all zero.

Lucky Numbers In Matrix: Find Min Row Max Col Elements

Find lucky numbers in matrix: identify row min & col max, then check each element if it's both min in row & max in col. Example usage in PHP.

Sort Jumbled Numbers By Mapped Values

Sort Jumbled Numbers: Map each digit in nums to its corresponding value in mapping array. Sort mapped values while preserving original order for equal values.

Number Of Good Leaf Node Pairs In Binary Tree

Count good leaf node pairs in binary tree: DFS traversal from each leaf node, stop when steps > distance. If another leaf within distance, add 1 to answer. Divide by 2 for double-counted pairs.

Sort Array By Increasing Frequency And Decreasing Value

Sort array by increasing frequency: count each value's freq, use custom comparator to sort by freq then value in dec order. PHP example: `array_count_values` & `usort` functions used.

Step-By-Step Directions From Binary Tree Node To Another

Find shortest path in binary tree from node s to t using DFS and LCA, returning step-by-step directions as string of 'L', 'R', and 'U' characters.

Maximum Score From Removing Substrings In PHP

Maximum points from removing substrings "ab" and "ba". Use stack to process string, prioritize higher value removals. Return max points after applying operations on s.

Crawler Log Folder: Min Operations To Main Folder

Crawler Log Folder: Min Operations Needed to Go Back to Main Folder. Count "../" operations to return to main folder after change folder ops. Example 1: ["d1/","d2/","../","d21/","./"] -> 2 operations.

Average Waiting Time Of Customers In A Restaurant

Average waiting time = (2 + 6 + 7) / 3 = 5 for customers [[1,2],[2,5],[4,3]]. Chef prepares food in order of arrival. Waiting time = finish time - arrival time.

Circular Game Winner Finder In Linear Time

Find winner of circular game: `return ($winner + $k) % $i;` formula used in Solution class finds the winner in linear time with constant space.

Merge Nodes In Between Zeros Into Single Node Values

Merge nodes in between zeros in linked list: sum adjacent non-zero values, replace with single node. Example: [0,3,1,0,4,5,2,0] -> [4,11].

Minimum Difference Between Largest And Smallest Value In Three Moves

Minimum difference between largest and smallest value in three moves is 0 after sorting array and removing elements from start or end.

Max Number Of Edges To Remove For Full Traversal

Remove max edges to keep graph fully traversable: use UnionFind to track Alice & Bob's traversal, sort edges by type and remove required ones.

Maximum Total Importance Of Roads Optimized

Maximum total importance of roads is achieved by assigning values optimally. The solution uses a greedy approach, sorting city counts and multiplying each value by its count. Example: n = 5, roads = [[0,1],[1,2],[2,3],[0,2],[1,3],[2,4]] returns 43.

Balancing Binary Search Trees In 60 Characters

Balance a Binary Search Tree: Given root of BST, return balanced BST with same node values. If multiple answers, return any. A balanced BST has depth difference of 1 in all nodes.

Longest Subarray With Absolute Diff Less Than Limit

Find longest subarray with abs diff <= limit: use 2 queues (min & max) to track elements. Slide window when diff > limit. Example: nums = [8,2,4,7], limit = 4 returns 2.

Maximize Magnetic Force Between Balls In Baskets

Distribute m balls into n baskets at positions[i] to maximize min magnetic force between ball pairs |x - y|, where x and y are ball positions. Return required force.

Minimum Moves To Seat Everyone In 4 Steps

Minimize moves to seat students: Sort seats & students arrays, then sum absolute differences between corresponding positions. Example: seats = [3,1,5], students = [2,7,4] returns 4.

Single Number III: Find Unique Elements In Linear Time And Space

Single Number III: Find two unique elements in an array of integers where all other elements appear twice. Use bitwise XOR and bit manipulation for linear runtime complexity and constant extra space.

Count Triplets With Equal XOR In Array

Count triplets that can form two arrays of equal XOR in an array of integers arr. Return the number of triplets (i, j and k) where a == b. Example: arr = [2,3,1,6,7], output: 4.

Number Of Steps To Reduce Binary Number To One

Reduce binary number to 1 in steps: if even, divide by 2; if odd, add 1. Example: "1101" -> 6 steps. Solution uses a while loop and substr to count steps.

Special Array With X Elements Greater Than Or Equal X

Array is special if there exists a number x such that exactly x numbers in nums are greater than or equal to x. Return x if array is special, otherwise return -1.

Counting Beautiful Subsets In An Array With Given Difference

Counting beautiful subsets in an array where no two elements differ by k is key. Algorithm uses DFS and dynamic counting to find all possible subsets, returning their count.

Maximum Sum Of Node Values Achievable With XOR Operation

Maximize node values sum in tree: XOR k with each node's value when edge is chosen. Return max achievable sum. Example: nums = [1,2,1], k = 3, edges = [[0,1],[0,2]] -> Output: 6.

Delete Leaves With Target Value In Binary Tree

Delete leaf nodes with value target in binary tree: recursively traverse and remove nodes where `val == target` and both children are null, until no more nodes meet this condition.

Evaluating Boolean Binary Trees With OR And AND Operations

Evaluate Boolean Binary Tree: Given a full binary tree with boolean OR and AND nodes, evaluate the root node's value based on its children's evaluations. Return True if the root evaluates to True, False otherwise.

Software Engineering And Web Development: Safest Path In Grid

Find the Safest Path in a Grid: Return the maximum safeness factor of all paths leading to cell (n - 1, n - 1) in a given grid, where safeness is defined as the minimum Manhattan distance from any cell in the path to any thief.

Largest Local Values In A Matrix: Finding 3x3 Max Values

Generate an integer matrix maxLocal of size (n - 2) x (n - 2) where maxLocal[i][j] is largest value in every contiguous 3x3 matrix in grid.

Doubling Linked List Numbers In O(1) Space

Double a number represented as a linked list by multiplying each digit by 2 and carrying over when necessary. Example: [1,8,9] becomes [3,7,8].

Remove Nodes With Greater Value In Linked List

Remove nodes from linked list where node's value is less than its right neighbor. Return modified linked list head. Example: [5,2,13,3,8] -> [13,8].

Letter Combinations Of Phone Number Digits

Phone number digit combinations: return all possible letter combinations that the number could represent using a given mapping of digits to letters.

Largest Positive Integer With Negative Counterpart Found

Find largest positive integer k in array where -k also exists. Iterate through nums, if -num is seen, update ans with max(ans, abs(num)). Return ans.

Word Search In Grids With Adjacent Cells

Word Search in Grids: Given an m x n grid of characters and a string word, return true if word exists in the grid, constructed from adjacent cells horizontally or vertically. Same letter cell may not be used more than once.

Reverse Prefix Of Word In 60 Characters

Reverse prefix of word: given string and char, reverse segment from start to first occurrence of char (inclusive). If char not found, return original string. Example: "abcdefd" with "d", result is "dcbaefd".

Calculating Nesting Depth Of Parentheses In VPS Strings

Maximum nesting depth of parentheses can be calculated by iterating through the string and keeping track of opened parentheses with a counter. The maximum value of this counter is the result.

Minimum XOR Operations To Equal K

Minimum operations to make array XOR equal to K: Flip bits in binary representation of elements until XOR equals k. Solution uses bitwise XOR and substr_count functions for efficient calculation.

Counting Unhappy Students: Sandwich Preferences And Queue Dynamics

Students unable to eat lunch due to sandwich mismatch. Algorithm counts students who can't take sandwiches based on their preference and stack order. Solution uses array count values and foreach loop to determine number of students left hungry.

Merge Two 2D Arrays By Summing Values Solution

Merge two 2D arrays by summing values: given two sorted arrays with unique ids, merge into one array, summing values for each id, and return sorted by id.

Minimum Operations To Satisfy Grid Conditions In 2D Matrix

Minimum operations needed to satisfy conditions in grid: min number of changes to make each cell equal to below it and different from right cell, if exists.

Find Edges In Shortest Paths: Boolean Array Of Edge Inclusion

Find Edges in Shortest Paths: Given undirected weighted graph, find boolean array where answer[i] is true if edge edges[i] is part of at least one shortest path from node 0 to n - 1.

Find Farmland Groups In Binary Matrix Land

Find all groups of farmland in a binary matrix: [[1,0,0],[0,1,1],[0,1,1]]. Return top left and bottom right corner coordinates for each group. Example output: [[0,0,0,0],[1,1,2,2]]