Java
Given an integer array, find the maximum length subarray having a given sum. #Data_structure
code.png
373.4 KB
We can use a map to solve this problem in linear time. The idea is to create an empty map to store the first subarray’s ending index, having a given sum. We traverse the given array and maintain the sum of elements seen so far.
* If the target is seen for the first time, insert the sum with its index into the map.
* If target-S is seen before, there is a subarray with the given sum that ends at the current index, and we update the maximum length subarray having sum S if the current subarray has more length.
#Source_code
#Data_strucutre
* If the target is seen for the first time, insert the sum with its index into the map.
* If target-S is seen before, there is a subarray with the given sum that ends at the current index, and we update the maximum length subarray having sum S if the current subarray has more length.
#Source_code
#Data_strucutre
code.png
2 MB
Huffman Coding Compression Algorithm
Huffman coding (also known as Huffman Encoding) is an algorithm for doing data compression, and it forms the basic idea behind file compression. This post talks about the fixed-length and variable length encoding, uniquely decodable codes, prefix rules, and Huffman Tree construction.
#Data_Strucutre
#Source_code
#133
Huffman coding (also known as Huffman Encoding) is an algorithm for doing data compression, and it forms the basic idea behind file compression. This post talks about the fixed-length and variable length encoding, uniquely decodable codes, prefix rules, and Huffman Tree construction.
#Data_Strucutre
#Source_code
#133