FastPrepPrefix-Length Letter Shifts
Problems/Prefix-Length Letter Shifts

Prefix-Length Letter Shifts

Chewy logoChewy● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Chewy phone screen. The report says the prefix length must be strictly less than the string length, but its examples use both ends. We follow the examples and allow both ends. Our version is about 98% the same as the reported question.

You are given a lowercase string s and an array shifts. Process shifts from left to right. For each value k, shift each of the first k letters of the current string forward by one alphabet position.

Letters wrap from z to a. Every prefix length is inclusive in the range 1 through s.length(). Return the final string after every shift is applied.

Function

shiftPrefixes(s: String, shifts: int[]) → String

Examples

Example 1

s = "abcd"shifts = [1,2,3,4]return = "eeee"

The successive strings are bbcd, cccd, dddd, and eeee.

Example 2

s = "aez"shifts = [1,1,3]return = "dfa"

The successive strings are bez, cez, and dfa; the final z wraps to a.

Example 3

s = "abc"shifts = [2,2,2]return = "dec"

The successive strings are bcc, cdc, and dec.

Constraints

  • 1 <= s.length() <= 200000.
  • 1 <= shifts.length <= 200000.
  • s contains only lowercase English letters.
  • 1 <= shifts[i] <= s.length().

Similar questions at other companies

  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
  • Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
  • Stars Between Bars in RangesExpedia · OAExpedia interview questions
  • Ordered IP FirewallDatabricks · PHONE SCREENDatabricks interview questions
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
  • Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
See Chewy hiring insights
Saved
class Solution {
    public String shiftPrefixes(String s, int[] shifts) {
        // Write your code here.
    }
}
Checking account…