Pattern recognition in data is a common challenge in computational problems. One such pattern involves identifying “hills” and “valleys” in…