---
# System prepended metadata

title: 2399. Check Distances Between Same Letters
tags: [Leetcode, Easy]

---

# 2399. Check Distances Between Same Letters
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/check-distances-between-same-letters/
## Code
```java=
class Solution {
    public boolean checkDistances(String s, int[] distance) {
        int len = s.length();
        int[] prev = new int[26];
        Arrays.fill(prev, -1);
        for(int i=0; i<s.length(); i++){
            int idx = s.charAt(i)-'a';
            if(prev[idx]==-1){
                prev[idx] = i;
            }
            else{
                int d = i-prev[idx]-1;
                if(distance[idx]!=d) return false;
            }
        }
        return true;
    }
}
```