Weekly Challenge 399
Each week Mohammad S. Anwar sends out The Weekly Challenge , a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. Unless otherwise stated, Copilot (and other AI tools) have NOT been used to generate the solution. It's a great way for us all to practice some coding.
Challenge , My solutions
Task 1: Longest Repeating Character
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.
My solution
To start this solution, I set string_length to the length of input_string .
from collections import Counter
def longest_repeating_char ( input_string : str , k : int ) -> int : string_length = len ( input_string )
Enter fullscreen mode
Exit fullscreen mode
I use a double loop.…