Hash Table

Minimum Window Substring

December 27, 2023
medium
Sliding Window, Hash Table

Problem # Given two strings s and t, return the minimum window in s which will contain all the characters in t. If there is no such window in s that covers all characters in t, return the empty string. Solution # The Python function min_window successfully finds the minimum window in the string s that contains all the characters of the string t. In the provided example with s = "ADOBECODEBANC" and t = "ABC", the function returned "BANC" as the smallest substring of s that includes all the characters in t. ...

Subarray Sum Equals K

December 26, 2023
medium
Hash Table, Cumulative Sum

Problem # Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals to k. Solution # To solve the problem of finding the total number of continuous subarrays whose sum equals a given integer k, a common and efficient approach is to use a cumulative sum combined with a hash table. This method allows us to efficiently track the sum of subarrays and check for the existence of the required sum. ...