HashMap : ===================== for HashMap we have 3 important methods 1. put 2. get 3. containsKey put it is used to insert a record get it is used to fetch the value of the key containsKey it is used to check wheather a key is there or not import java.util.*; class HelloWorld { public static void main(String[] args) { System.out.println("Try programiz.pro"); HashMap hm=new HashMap<>(); hm.put(1,3); hm.put(2,6); System.out.println(hm.get(2)); System.out.println(hm.containsKey(2)); System.out.println(hm.containsKey(10)); } } 2 pointers and sliding window ============================================= 1. first we need to create one dummy array 2. fill the particular index by using that value int arr[]={1,2,3,4,6,7,8}; =========================================== import java.util.*; class HelloWorld { public static void main(String[] args) { int arr[]={1,5,2,6,7}; int dummy[]=new int[8]; for(Integer i:arr){ dummy[i]++; } for(int i=1;i findDuplicates(int[] arr) { // code here HashMap hm=new HashMap<>(); for(Integer i:arr){ if(hm.containsKey(i)){ int x=hm.get(i); x++; hm.put(i,x); }else{ hm.put(i,1); } } ArrayList al=new ArrayList<>(); for(Map.Entry me:hm.entrySet()){ if(me.getValue()>1){ al.add(me.getKey()); } } return al; } } =============================================================