Solve Selective String Compression using Lua to enhance your skills with lua coding practice , master coding concepts, and prepare for interviews with practical exercises and detailed solutions.
Difficulty : Medium
Categories :
Given a string s and an integer k, design a string compression algorithm that works as follows:
Return the compressed string.
Input: s = "aaabbbcccc", k = 2 Output: "aaa3c4" Explanation: 'aaa' length=3 > k=2, compress to 'a3' 'bbb' length=3 > k=2, compress to 'b3' 'cccc' length=4 > k=2, compress to 'c4'
Input: s = "abbbccdddd", k = 3 Output: "abbbccd4" Explanation: 'a' length=1 ≤ k=3, keep as 'a' 'bbb' length=3 ≤ k=3, keep as 'bbb' 'cc' length=2 ≤ k=3, keep as 'cc' 'dddd' length=4 > k=3, compress to 'd4'
Real-World Applications Solve problems inspired by Lua's common use cases, such as game development and embedded systems.
Step-by-Step Guidance Break down Lua's concepts into digestible lessons.
Practical Skills Build hands-on experience with Lua for real-world projects.