The core concept is to find the target from a sorted array which is quite suitable to use binary serach I think.
Here are my instructions:
Get the middle element, mid
Compare the mid with the target. there will be 3 branches: a. target < mid: continue to find the target from the LEFT side of the mid b. target > mid: continue to find the target from the RIGHT side of the mid c. target = mid: In this case, [index_of_mid, index_of_mid] will be our base answer so keep it. Then based on this answer, we need to go further to the both left and right to seek if there is other elements match to the search target.
For example, if the given array is [1, 2, 3, 4, 4, 4, 4, 6, 9], and the search target is 4.
Then we are trying to get this green range.
When we go through the instructions, we will get the middle element, and hit the c case.
Then base on this position, we seek towar left and right to get the final range.