FastPrepMost Relevant Text Span
Problems/Most Relevant Text Span

Most Relevant Text Span

Hebbia logoHebbia● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Hebbia phone screen. The report gives a string with a relevance score for each character. You find the most relevant stretch of the string. Our version is about 92% the same as the reported question.

You are given a nonempty lowercase string text and an integer array scores of the same length. The relevance of a nonempty contiguous span is the sum of the scores aligned with its characters.

Return the substring with the largest relevance. If several spans have the same largest relevance, return the one with the earliest starting index. If they also have the same starting index, return the shortest one.

Function

mostRelevantSpan(text: String, scores: int[]) → String

Examples

Example 1

text = "search"scores = [-2,4,3,-5,2,1]return = "ea"

The span "ea" has relevance 4 + 3 = 7, which is the largest possible sum.

Example 2

text = "matrix"scores = [-4,-2,-7,-1,-5,-3]return = "r"

Every score is negative. The single character "r" has score -1, the largest available relevance.

Example 3

text = "abcd"scores = [1,-1,1,-1]return = "a"

Several spans have relevance 1. The earliest starts at index 0, and "a" is the shortest span with that start and score.

Constraints

  • 1 ≤ text.length = scores.length ≤ 2 * 10^5.
  • text contains only lowercase English letters.
  • -10^9 ≤ scores[i] ≤ 10^9.

More Hebbia interview questions

  • Ultimate Tic-Tac-Toe Move SimulatorPHONE SCREEN · Seen May 2026
  • Detect a Winner on a 3x3 Tic-Tac-Toe BoardONSITE INTERVIEW · Seen Jun 2026
  • LRU Cache Snapshot PrinterONSITE INTERVIEW · Seen Feb 2026

Similar questions at other companies

  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
  • Jump Game IINavi · PHONE SCREEN
  • Best Stock Profit With a Sell FeeKaseya · PHONE SCREEN
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Biggest Number From Gluing Numbers TogetherAdobe · PHONE SCREENAdobe interview questions
  • Return a Minimum-Coin Change BreakdownDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
See Hebbia hiring insights
Saved
class Solution {
    public String mostRelevantSpan(String text, int[] scores) {
        // Write your code here.
    }
}
Checking account…