<s>[INST] I need help with an algorithm that can find a target value in a sorted array that has duplicate values. If the target value is not found in the array, the algorithm should return -1. This is similar to the binary search algorithm, but with a tweak to handle duplicates. Any ideas?[/INST]