I came across a programming exercise and was stuck. The problem is:
You need to define a valid password for an email but the only restrictions are:
The password must contain one uppercase character and the password should not have numeric digit.
Now, given a String, find the length of the longest substring which is a valid password.
I am able to solve this in Java but not able to figure out how to do in javascript.
Here is my Java solution:
public int lengthOfLongestSubstring(String s) {
    int n = s.length();
    Set<Character> set = new HashSet<>();
    int ans = 0, i = 0, j = 0;
    while (i < n && j < n) {
        if (!set.contains(s.charAt(j))){
            set.add(s.charAt(j++));
            ans = Math.max(ans, j - i);
        }
        else {
            set.remove(s.charAt(i++));
        }
    }
    return ans;
}
 
     
     
    