Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    2399 - Check Distances Between Same Letters\.

    Easy

    You are given a 0-indexed string s consisting of only lowercase English letters, where each letter in s appears exactly twice. You are also given a 0-indexed integer array distance of length 26.

    Each letter in the alphabet is numbered from 0 to 25 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, ... , 'z' -> 25).

    In a well-spaced string, the number of letters between the two occurrences of the <code>i<sup>th</sup></code> letter is distance[i]. If the <code>i<sup>th</sup></code> letter does not appear in s, then distance[i] can be ignored.

    Return true if s is a well-spaced string, otherwise return false.

    Example 1:

    Input: s = "abaccb", distance = 1,3,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

    Output: true

    Explanation:

    • 'a' appears at indices 0 and 2 so it satisfies distance0 = 1.

    • 'b' appears at indices 1 and 5 so it satisfies distance1 = 3.

    • 'c' appears at indices 3 and 4 so it satisfies distance2 = 0.

    Note that distance3 = 5, but since 'd' does not appear in s, it can be ignored.

    Return true because s is a well-spaced string.

    Example 2:

    Input: s = "aa", distance = 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

    Output: false

    Explanation:

    • 'a' appears at indices 0 and 1 so there are zero letters between them. Because distance0 = 1, s is not a well-spaced string.

    Constraints:

    • 2 &lt;= s.length &lt;= 52

    • s consists only of lowercase English letters.

    • Each letter appears in s exactly twice.

    • distance.length == 26

    • 0 &lt;= distance[i] &lt;= 50

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Boolean checkDistances(String s, IntArray distance)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait