you give 0indexed integer array num an index hill num close nonequal neighbor small numsi Similarly index valley num close nonequal neighbor large numsi Adjacent indice j hill valley numsi numsjNote index hill valley nonequal neighbor leave right indexreturn number hill valley num Example 1input num 241165output 3explanationat index 0 there nonequal neighbor 2 leave index 0 hill valleyAt index 1 the close nonequal neighbor 4 2 1 since 4 2 4 1 index 1 hill at index 2 the close nonequal neighbor 1 4 6 since 1 4 1 6 index 2 valleyAt index 3 the close nonequal neighbor 1 4 6 since 1 4 1 6 index 3 valley note valley index 2at index 4 the close nonequal neighbor 6 1 5 since 6 1 6 5 index 4 hillAt index 5 there nonequal neighbor 5 right index 5 hill valley there 3 hill valley return 3example 2input num 665541output 0explanationat index 0 there nonequal neighbor 6 leave index 0 hill valleyAt index 1 there nonequal neighbor 6 leave index 1 hill valleyAt index 2 the close nonequal neighbor 5 6 4 since 5 6 5 4 index 2 hill valleyAt index 3 the close nonequal neighbor 5 6 4 since 5 6 5 4 index 3 hill valleyAt index 4 the close nonequal neighbor 4 5 1 since 4 5 4 1 index 4 hill valleyAt index 5 there nonequal neighbor 1 right index 5 hill valleythere 0 hill valley return 0 constraints3 numslength 1001 numsi 100