Subarrays with distinct elements hashing and tries

import java.util.*;
public class Main {

public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int j=0;
	int ans = 0;
	int[] arr = new int[n];
	HashSet<Integer> set = new HashSet<>();
	for(int i=0;i<n;i++) {
		arr[i] = sc.nextInt();
	}
	
	for(int i=0;i<arr.length;i++) {
		while(j<n && !set.contains(arr[j])) {
			set.add(arr[i]);
			j++;
		}
		
		ans += ((j-i)*(j-i+1))/2;
		set.remove(arr[i]);
	}
	
	System.out.println(ans);
}

}

//sir I’m failing two of the test cases, suggest any changes in code

@Siddharth_sharma1808,
https://ide.codingblocks.com/s/227092 corrected code.
I have highlighted the error line.