FastPrepExtraordinary Substrings
Problems/Extraordinary Substrings

Extraordinary Substrings

Palantir logoPalantir● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Palantir new grad online assessment. The FDSE author names Extraordinary Substrings and mentions prefix sums, but does not give the full definition. A separate Palantir online assessment report shows the same named task and gives the letter mapping, the divisibility rule, and the 2,000-letter limit used here.

We used that related definition. The added examples and tests are our data. The related report does not add an FDSE sighting or a date it was seen.

Our version is about 50% the same as the FDSE report.

Each lowercase English letter has a value:

  • ab map to 1.
  • cde map to 2.
  • fgh map to 3.
  • ijk map to 4.
  • lmn map to 5.
  • opq map to 6.
  • rst map to 7.
  • uvw map to 8.
  • xyz map to 9.

A nonempty contiguous substring is extraordinary when the sum of its letter values is divisible by its length.

Return the number of extraordinary substrings of input_str. Count occurrences at different positions separately, even when their text is equal.

Function

countSubstrings(input_str: String) → int

Examples

Example 1

input_str = "bdh"return = 4

Each single letter is extraordinary. The full string has values 1, 2 and 3, with sum 6 divisible by length 3. The pairs have sums 3 and 5, so neither qualifies. There are 4 occurrences.

Example 2

input_str = "asdf"return = 6

The four single letters qualify. The pair as has sum 8 and length 2; sdf has sum 12 and length 3. The other pairs, asd and the full string fail divisibility. There are 6 occurrences.

Example 3

input_str = "abc"return = 4

The three single letters qualify. The pair ab has sum 2 and length 2. The pair bc has sum 3 and the full string has sum 4, so neither qualifies. There are 4 occurrences.

Constraints

  • 1 <= input_str.length <= 2000.
  • input_str contains only lowercase English letters a through z.

More Palantir Online Assessment questions

  • Basic Item DiscountsOA · Seen Nov 2026
  • Optimize Discount Selection Under a Point BudgetOA · Seen Nov 2026
  • Stacked Item and Category DiscountsOA · Seen Nov 2026
  • Minimize Path ValueOA · Seen Sep 2024
  • No Pairs AllowedOA · Seen Sep 2024
  • REST API: Country CodesOA · Seen Feb 2024
  • Swap ParityOA · Seen Feb 2024
  • Freelance Candidate ReviewOA · Seen Nov 2023
  • Benchmarking Tool ReportOA · Seen Sep 2023
  • Count Fit Records Across PagesOA · Seen Sep 2023

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
  • Number of Divisible Substrings (For MLE)Wayfair · OAWayfair interview questions
  • Longest Equal-Frequency SubstringDRW · PHONE SCREENDRW interview questions
  • Weighted Next-Word Prediction From Training SequencesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions

Interview reports that mention this question

  • Palantir FDSE New Grad OA Questions: 6 Experiences (Part 2 of 2)

Palantir interview experiences

  • Palantir FDSE Experienced-Hire Interviews: 5 Experiences
  • Palantir FDSE New Grad Interviews: 5 Experiences (Part 1 of 2)
  • Palantir FDSE Intern OA and Interviews: 3 Experiences
  • Palantir FDSE Karat and Learning: 7 Experiences (Part 2 of 2)
  • Palantir FDSE OA and Interviews: 16 Experiences (Part 1 of 2)
All Palantir interview questionsSee Palantir hiring insights
Saved
class Solution {
    public int countSubstrings(String input_str) {
        // Write your code here.
    }

}
Checking account…