Given an array of integers, write an optimized algorithm to find the longest subarray with a sum equal to a target value.