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

Take K Of Each Character From Left And Right In Minimum Time

Take K of Each Character From Left and Right: Use sliding window technique with two pointers to find min minutes needed to take at least k of each char ('a', 'b', 'c') from left & right of string.

Shortest Subarray With Sum At Least K

Given an array and an integer k, return the length of the shortest subarray with sum at least k. Use prefix sums and a monotonic queue for efficient solution.

Counting Fair Pairs In An Array With Binary Search And Sorting

Count fair pairs in array nums with lower <= nums[i] + nums[j] <= upper. Sort nums, use binary search for bounds & count valid indices.

Integrating Stripe Treasury API With PHP For Financial Services

Integrate Stripe Treasury API with PHP: Install SDK, set up account & keys, create financial accounts, fund & transfer funds, monitor transactions. Follow 8 steps for seamless integration.

Laravel Third Party API Integration Guide In 8 Steps

Integrate 3rd party APIs in Laravel with step-by-step guide & examples: set up API keys, install Guzzle, create service class, bind service, define routes & build view.

Largest Combination With Bitwise AND Greater Than Zero

Find largest combination of candidates with bitwise AND > 0. Count numbers with set bits at each position (0-23). Return max count as largest combination size.

Minimum Changes To Make Binary String Beautiful In 60 Characters

Make binary string beautiful by partitioning into substrings with even length & only 1's or 0's. Change minority char in each block to match majority. Time complexity: O(n), space complexity: O(1).

String Compression III: Compressing Strings With PHP

Compress string using greedy approach: take longest prefix of repeating chars (up to 9) and append count & char. Example: 'abcde' -> '1a1b1c1d1e', 'aaaaaaaaaaaaaabb' -> '9a5a2b

Check If String Can Become Goal Through Rotations In PHP

Rotate string s into goal by checking if goal is a substring of s + s. If lengths match and goal exists in doubleS, return true; otherwise, false. Time complexity: O(n), space complexity: O(n).

Minimum Removals To Make Mountain Array

Given an array nums, return min elements to remove to make it a mountain array. Use dynamic programming to find max mountain subsequence and compute min removals.

Maximum Moves In Grid With Dynamic Programming

Dynamic Programming solution for Maximum Number of Moves in a Grid: Initialize dp array with 0s, traverse grid from last column to first, update dp values based on possible moves, and return max value in first column.

12 Key Takeaways From Solving Over 200 LeetCode Problems

Pattern recognition is key to solving LeetCode problems. Consistently reinforcing algorithmic foundations & optimizing problem-solving approaches helps tackle complex problems with ease.

Laravel's SaveQuietly(): Silently Saving Models Without Events

In Laravel, use `saveQuietly()` to update models silently, bypassing events like logging & notifications, ideal for bulk updates or admin overrides.

Splitting Strings Into Max Unique Substrings

Split string into max unique substrings using backtracking & set for uniqueness. Recursive function explores all possible substrings, backtracks if repetition occurs.

Counting Maximum Bitwise-OR Subsets In PHP

Count Number of Maximum Bitwise-OR Subsets: Calculate max bitwise OR, enumerate subsets (2^n), count valid subsets with max OR. PHP solution for arrays up to size 16.

Longest Happy String With Greedy Approach

We can use a greedy algorithm to find the longest happy string by using a Priority Queue (Max Heap) and continuously extracting the character with the highest count while ensuring we don't exceed two consecutive occurrences of the same character.

Smallest Range Covering Elements From K Sorted Lists

Find smallest range covering elements from k lists: use min-heap & sliding window to track smallest element from each list. Time complexity: O(n * log k), space complexity: O(k).

Divide Intervals Into Minimum Number Of Groups

Divide intervals into min groups: Sort events by time, track ongoing intervals & max overlap, return max count of overlapping intervals at any point.

Maximum Width Ramp In Array With PHP Solution

Maximum width ramp in an array is achieved by maintaining a decreasing stack of indices and traversing from the end, updating maximum width whenever nums[i] <= nums[j]. Time complexity is O(n).

Minimum String Length After Removing Substrings

Minimize string length by removing 'AB' and 'CD' substrings using stack approach. Traverse string, push chars onto stack, pop if top 2 form 'AB' or 'CD'. Resulting length = stack size.

Can Array Pairs Be Divisible By K In O(n) Time?

Check if array pairs are divisible by k: use frequency count of remainders and check pairing conditions for efficient solution in O(n) time complexity.

How To Start Testing In PHP With PHPUnit Step-by-Step Guide

Install PHPUnit via Composer, create a sample class & test case, arrange, act, assert, run tests & expand with new methods for robust testing.

Extra Characters In String: Min Extra Char Left Over

Break string s into non-overlapping substrings from dictionary. Min extra chars = dp[len(s)]. DP[i] = min(dp[i-1]+1, min(dp[j]) if s[j:i] in dict).

Maximizing Binary Matrix Score With Row And Column Flipping

Maximize binary matrix score by flipping rows & columns to ensure most significant bits are 1 and maximize remaining bits. Calculate final score by interpreting each row as a binary number.

Lexicographical Numbers In O(n) Time And O(1) Space

Lexicographical Numbers: Sort numbers from 1 to n in lexicographical order using DFS-like strategy. O(n) time complexity and O(1) extra space used.

Create Data Transfer Objects (DTOs) Using Laravel Data

Create Data Transfer Objects (DTOs) with Laravel Data: Install package, define properties & types, use in controllers, transform data & handle collections.

Largest Number From Array Of Integers

Arrange non-negative integers to form largest number. Compare concatenated results using custom comparator. Edge case: if largest num is 0, return '0'. Time complexity: O(n log n) + O(n).

Sum Of Distances In Tree: Efficient DFS Approach For Large Trees

Sum of Distances in Tree: Use DFS & dynamic programming to compute sum of distances for each node. Two traversals: first calculates subtree sizes & total distance from root, second adjusts results based on parent's result.

Uncommon Words From Two Sentences: Find Unique Words In Strings

Uncommon Words from Two Sentences: Split sentences into words, count occurrences with hash table, filter uncommon words. Time complexity O(n+m), space complexity O(n+m).

K-th Smallest Prime Fraction In PHP

Binary Search on Fractions: count valid fractions and track largest fraction smaller than midpoint m, return when count matches k or adjust search range accordingly.

Preventing SQL Injection Attacks In PHP Applications

Prevent SQL injection attacks in PHP by using prepared statements with MySQLi or PDO to separate SQL logic from data, ensuring user input is treated as data rather than executable code.

Valid Parenthesis String In 60 Characters

Valid Parenthesis String: Use greedy approach with two counters (minOpen & maxOpen) to track possible open parentheses. If maxOpen < 0 or minOpen > 0 at end, string is invalid.

Insert GCD Nodes In Linked List With PHP Solution

We need to insert nodes between every pair of adjacent nodes in a linked list with values equal to the greatest common divisor (GCD) of them. We'll traverse the list, calculate GCD for each pair and insert new nodes accordingly.

PHP Sessions: Secure User Data Across Pages

PHP Sessions: Store user-specific data on the server, persist across pages, and enhance security with session_start(), $_SESSION array, and session_destroy().

PHP Metaprogramming Techniques Explained

PHP Metaprogramming: Writing code that generates or manipulates other code using Reflection API, Magic Methods, Eval Function, Anonymous Functions & Closures.

Add One Row To Binary Tree In Depth-First Search

Add one row to binary tree at specified depth using DFS or BFS traversal and insert new nodes with value val as left and right children of each node.

Introduction To The Repository Pattern In Laravel For Cleaner Code

Learn how to implement the Repository Pattern in Laravel for cleaner, more modular code. Abstracts data access logic, promotes separation of concerns & loose coupling, making it easier to switch databases or storage engines.

Dynamic Programming Solution For Student Attendance Records

Dynamic Programming solution for Student Attendance Record II: count valid records with <2 absences & no 3+ late days. Modular arithmetic handles large numbers.

Optimizing Slow SQL Queries For Database Efficiency

Slow SQL queries impact app performance. Identify common issues like indexing, joins, and sorting, then optimize using techniques like connection pooling and query rewriting.

Relative Ranks Of Athletes In Competition

Relative Ranks: Sort scores in descending order, assign 'Gold Medal', 'Silver Medal', 'Bronze Medal' ranks, then numeric rank for 4th+ place. PHP solution: arsort(), loop over original array.

Island Perimeter Calculation In PHP: A Simple Approach

Calculate island perimeter: iterate through grid, add 4 for each land cell, subtract 2 for shared edges with neighbors. Example usage: $grid = [[0,1,0,0],[1,1,1,0],[0,1,0,0],[1,1,0,0]]; echo islandPerimeter($grid); // Output: 16

Sum Of Left Leaves In Binary Tree: Recursive Solution

404. Sum of Left Leaves: Given binary tree root, return sum of all left leaves. A leaf is node with no children, left leaf is left child of another node. Example usage and solution provided.

Remove K Digits From String For Smallest Number

Remove K Digits: Use stack-based greedy approach to build smallest possible number by removing k digits from input string num. Handle leading zeros and edge cases.

N-ary Tree Postorder Traversal In PHP

Postorder traversal of n-ary tree: use stack to reverse recursion, push children first then parent node. Example: [5,6,3,2,4,1] for input [1,null,3,2,4,null,5,6]

Reverse String In Place With O(1) Extra Memory

Reverse String: Use two pointers, one at start & end, swap elements & increment left, decrement right until left < right. Time complexity O(n), space complexity O(1).

Patching Array: Min Patches Required For Range Coverage

Minimize patches required to cover range [1,n] with array nums using greedy algorithm. Initialize miss=1, loop until miss>n: if current num covers miss, add it; else patch miss & double range.