Question: Make run time faster. Optimize code # Complete the 'compressword' function below. # # The function is expected to return a STRING. # The function

Make run time faster. Optimize code
\# Complete the 'compressword' function below. \# \# The function is expected to return a STRING. \# The function accepts following parameters: \# 1. STRING word # 2. INTEGER k \# def compressWord (word: str, k: int): \# Write your code here while True: finalChar = False for i in range (len (word) k+1 ): if len(set(word[i:i+k]))==1 : word = word [:i]+word[i+k:] finalChar = True break if not finalchar: break return word
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
