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.
I am a Technical Lead with holistic knowledge of software development and design. I am also experienced in coordinating with stakeholders
Add fractions with PHP: parse input string, compute result step by step, simplify final fraction. gcd function & addFractions function used for simplification.
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
Delete node in linked list: copy next node's value into current node & update next pointer to skip over next node.
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.
Alice and Bob play optimally, return max stones Alice can get with dynamic programming and prefix sum calculation.
Minimum operations to get 'A' exactly n times: dp[i] = min(dp[d] + 1) for all divisors d of i.
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.
Maximize points by picking cells in each row while minimizing cost of switching between rows using dynamic programming and auxiliary arrays left and right.
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.
Can provide correct change with bills = [5,5,5,10,20] but not with bills = [5,5,10,10,20].
Maximal Rectangle problem: find largest rectangle containing only 1's in binary matrix. Use dynamic programming & stack-based approach to calculate maximal area.
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)
Minimum days to disconnect island: 2 if grid is connected, 1 if single cell removal disconnects it, otherwise 2.
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: 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.
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.
Convert non-negative integer num to English words representation using recursion & helper function. Handle edge cases like 0 & numbers with intermediate chunks as zero.
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.
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.
Count Senior Citizens: Extract age from details array, convert to int, check if > 60. Loop through each detail, increment counter for seniors. Return count.
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.
Count 1's, extend array, use Sliding Window technique to find min swaps for circular binary array
Create a weather app with PHP, jQuery, AJAX, Bootstrap & MySQL: fetch data from API, save to database, display on frontend
Comprehensive contact form app built with PHP, jQuery, AJAX & MySQL, storing details in a relational database and sending email notifications upon submission.
Minimize bookshelf height by placing books with total thickness <= shelfWidth on each level. Use dynamic programming to track min height after placing each book.
Minimum deletions needed to make string balanced: delete max of 'b's before each index and 'a's after it. Time complexity O(n).
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.
Find longest substring without repeating chars: use sliding window & hash map to track char indices. Time complexity O(n). Example usage in PHP.
Solve graph problem with traffic signals: find second minimum time to reach destination from vertex 1 to n in a bi-directional connected graph.
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.
Implementing Floyd-Warshall's algorithm to find shortest paths between all pairs of cities and then calculating reachable cities within distanceThreshold.
Build a k x k matrix satisfying row and column conditions using topological sorting and graph theory.
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 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.
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: Map each digit in nums to its corresponding value in mapping array. Sort mapped values while preserving original order for equal values.
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: 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.
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.
Parse chemical formula, count atoms, and return sorted string of elements with counts (if > 1). Example: "H2O" -> "H2O", "Mg(OH)2" -> "H2MgO2".
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 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 = (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.
Find winner of circular game: `return ($winner + $k) % $i;` formula used in Solution class finds the winner in linear time with constant space.
Max water bottles drinkable = numBottles + (numExchange * ((numBottles - 1) / numExchange)) + numBottles.
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 is 0 after sorting array and removing elements from start or end.
Three consecutive odds in array return true if found false otherwise. Solution iterates through array checking each triplet for odd numbers.
Remove max edges to keep graph fully traversable: use UnionFind to track Alice & Bob's traversal, sort edges by type and remove required ones.
Return list of ancestors for each node in DAG: [[],[],[0,1],[0,2],[0,1,3],[0,1,2,3,4],[0,1,2,3]]
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.
Find center of star graph: return edge with most common node, which is connected to every other node.
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.
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.
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.
Return min days to make m bouquets from garden: if (m * k > n) return -1; else binary search for mid where canMakeBouquets >= m
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.
Append characters to end of s so t becomes subsequence: return strlen($t) - $i; where i is index of last matched char in t.
Calculate score of string by summing absolute differences between ASCII values of adjacent characters.
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 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.
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.
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 where no two elements differ by k is key. Algorithm uses DFS and dynamic counting to find all possible subsets, returning their count.
Generate all subsets from given unique integers, no duplicates allowed, return in any order
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 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.
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.
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.
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.
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 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].
Phone number digit combinations: return all possible letter combinations that the number could represent using a given mapping of digits to letters.
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: 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: 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".
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 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.
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: given two sorted arrays with unique ids, merge into one array, summing values for each id, and return sorted by id.
Find number of subarrays where boundary elements are max in nums, return count. Example: [1,4,3,3,2] has 6 such subarrays.
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: 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 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]]