We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The two-pointer approach reduces the number of iterations compared to a simple linear search.
publicstaticintintroTutorial(intV,List<Integer>arr){// Write your code herefor(inti=0,j=arr.size()-1;i<j;i++,j--){if(Objects.equals(arr.get(i),V)){returni;}if(Objects.equals(arr.get(j),V)){returnj;}}return-1;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Intro to Tutorial Challenges
You are viewing a single comment's thread. Return to all comments →
The two-pointer approach reduces the number of iterations compared to a simple linear search.