Prefix-Length Letter Shifts
Updated
Problem statement
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[]) → StringExamples
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.scontains 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