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.