Tap here to switch tabs
Problem
Submissions

Problem: Check Distances Between Same Letters

med
30 min
Try to solve the Check Distances Between Same Letters problem.

Statement

You are given a 00 indexed string s consisting of lowercase English letters, where every letter present in s appears exactly twice. You are also given a 00 indexed integer array distance of length 2626.

The alphabetical letters are mapped to indices from 00 to 2525 (that is, 'a' corresponds to 00, 'b' corresponds to 11, and so on, up to 'z' which corresponds to 2525).

A string s is considered well spaced if, for every letter that appears in s, the number of characters strictly between its two occurrences is equal to distance[i], where i is the 00 indexed alphabetical position of that letter. If a letter does not appear in s, its corresponding value in distance can be ignored.

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

Constraints:

  • 2≤2 \leq s.length ≤52\leq 52

  • s consists only of lowercase English letters.

  • Each letter appears in s exactly twice.

  • distance.length =26= 26

  • 0≤0 \leq distance[i] ≤50\leq 50

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Check Distances Between Same Letters

med
30 min
Try to solve the Check Distances Between Same Letters problem.

Statement

You are given a 00 indexed string s consisting of lowercase English letters, where every letter present in s appears exactly twice. You are also given a 00 indexed integer array distance of length 2626.

The alphabetical letters are mapped to indices from 00 to 2525 (that is, 'a' corresponds to 00, 'b' corresponds to 11, and so on, up to 'z' which corresponds to 2525).

A string s is considered well spaced if, for every letter that appears in s, the number of characters strictly between its two occurrences is equal to distance[i], where i is the 00 indexed alphabetical position of that letter. If a letter does not appear in s, its corresponding value in distance can be ignored.

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

Constraints:

  • 2≤2 \leq s.length ≤52\leq 52

  • s consists only of lowercase English letters.

  • Each letter appears in s exactly twice.

  • distance.length =26= 26

  • 0≤0 \leq distance[i] ≤50\leq 50