Custom String Compression
Function Name: compressString
Description
Write a function that performs a basic string compression using the counts of consecutive repeated characters.
For example, the string 'aabcccccaaa' would become 'a2b1c5a3'.
If the compressed string is not smaller than the original string, your function should return the original string.
The function should handle uppercase and lowercase letters separately, meaning 'Aa' should be compressed as 'A1a1'.
Requirements
- The function 'compressString' must take a single parameter: the string to be compressed.
- The compression should count consecutive repeated characters and represent them as the character followed by the count.
- The function must return the original string if the compressed string is not shorter.
- Only alphabetic characters (uppercase and lowercase) will be included in the input string.
- The function should be case-sensitive, treating uppercase and lowercase characters as distinct.
Examples
compressString('aabcccccaaa') should return 'a2b1c5a3'.compressString('abcd') should return 'abcd'.compressString('AAb') should return 'A2b1'.compressString('aA') should return 'a1A1'.
Unique Character Mapping
Mon Dec 23 2024
Create a function named isIsomorphic that takes two strings and determines if they are isomorphic. Two strings are isomorphic if the characters in the first string can be replaced to get the second string. The replacement must be consistent for all occurrences of a character and no two characters may map to the same character, but a character may map to itself.
Circular Queue Implementation
Wed Dec 25 2024
In this challenge, you are required to implement a Circular Queue, a linear data structure that follows the First In First Out principle with a fixed size. The Circular Queue should wrap around to the beginning when the queue reaches its end. The implementation should support basic operations like enqueue (add an element), dequeue (remove an element), peek (get the element at the front of the queue), and an isEmpty method to check if the queue is empty.