Unique Characters In String: O(1) Space Complexity
Two approaches to find repeated char in string: frequency array & bit masking. Time complexity O(N), space complexity O(1). Code provided.
ML Researcher | Problem solver
Two approaches to find repeated char in string: frequency array & bit masking. Time complexity O(N), space complexity O(1). Code provided.
Max subarray sum & min absolute sum using Kadane's algorithm. Time complexity O(N), space complexity O(1). Code: class Solution { public int maxAbsoluteSum(int[] nums) {...} }
Reorder a linked list by reversing the second half and combining it with the first half. Time complexity: O(N), Space complexity: O(1).
Implement Stock Spanner with O(n) time complexity and O(n) space complexity. Use a list to store price and span, jumping to last day's span when current price is less than previous prices.
Sort colors in O(N) time complexity using counting sort. Initialize counters for zeros and ones, then place them in the array accordingly.
Optimized solution to set zeros in a matrix. Use two boolean vars to track first row & col with zero, then iterate through rest of matrix to mark rows & cols with zero.