Menu

PWC 399
📰

PWC 399

DEV Community: perl·Bob Lied·about 15 hours ago
#o9xJUQSa
#devtoperl#devto#dev#node#length
Reading 0:00
15s threshold

This week's tasks are about length, so let's cue up the Eagles Long Run album from 1979 and get to work.

Task 1: Longest Repeating Character

Task Description

You are given a string str and an integer k > 0. Write a script to choose any character of str and change it to another character. You may perform this operation up to k times. Return the length of the longest reachable substring of a single letter.

Example 1: Input: $str = "AAAAA", $k = 2

Output: 5

Every character in the string is already the same letter "A". The maximum operations allowed (k = 2) do not even need to be used. The entire string of length 5 is already the longest valid substring.

Example 2: Input: $str = "ABCDE", $k = 4

Output: 5

All 5 characters in the string are distinct. The most frequent character occurs only 1 time. To turn the entire string into a single repeated character, we need to replace 5 - 1 = 4 characters.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.