FastPrepNumber of Divisible Substrings (For MLE)
Problems/Number of Divisible Substrings (For MLE)

Number of Divisible Substrings (For MLE)

Wayfair logoWayfair● EasyNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Each character of the English alphabet has been mapped to a digit as shown below.

A string is divisible if the sum of the mapped values of its characters is divisible by its length.

Given a string s, return the number of divisible substrings of s.

A substring is a contiguous non-empty sequence of characters within a string.

Function

numberOfDivisibleSubstrings(word: String) → int

Examples

Example 1

word = "asdf"return = 6
Example 1 illustration

The table above contains the details about every substring of word, and we can see that 6 of them are divisible.

Example 2

word = "bdh"return = 4

The 4 divisible substrings are: "b", "d", "h", "bdh". It can be shown that there are no other substrings of word that are divisible.

Example 3

word = "abcd"return = 6

The 6 divisible substrings are: "a", "b", "c", "d", "ab", "cd". It can be shown that there are no other substrings of word that are divisible.

Constraints

  • 1 <= word.length <= 2000
  • word consists only of lowercase English letters.

More Wayfair interview questions

  • UCB1 Multi-Armed Bandit TraceONSITE INTERVIEW · Seen Sep 2026
  • Container With Most WaterPHONE SCREEN · Seen Sep 2026
  • Assign Distinct Letter Values to Minimize XORPHONE SCREEN · Seen Sep 2026
  • Moving Cost by Volume and CategoryONSITE INTERVIEW · Seen Sep 2026
  • DFS Subsequences of a String (For MLE)OA · Seen Sep 2024
  • Smash The Bricks(NG)OA · Seen Apr 2024
  • Validating Magical Binary Strings with RegEx (NG)OA · Seen Apr 2024
  • First Three Badge Times per UserPHONE SCREEN · Seen Apr 2022
  • Time of Maximum Mall OccupancyPHONE SCREEN · Seen Apr 2022
  • Longest Common Contiguous User ActionsPHONE SCREEN · Seen Apr 2022

Similar questions at other companies

  • Shortest Digit Prefix for Target MultisetsVisa · OAVisa interview questions
  • Longest Balanced Substring After One SwapTekion · OATekion interview questions
  • Count Special StringsAmazon · OA
  • Longest Substring with Even OccurrencesDeloitte · OADeloitte interview questions
  • Extraordinary SubstringsPalantir · OAPalantir interview questions
  • Longest Equal-Frequency SubstringDRW · PHONE SCREENDRW interview questions
  • Weighted Next-Word Prediction From Training SequencesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
All Wayfair interview questionsSee Wayfair hiring insights
Saved
class Solution {
    public int numberOfDivisibleSubstrings(String word) {
      // write your code here (You might want to refer to LC 2950 :)
    }

}
Checking account…