General String Algorithms Algorithm

The General String Algorithms (GSA) is a collection of algorithms used for various string manipulation and processing tasks. These algorithms are designed to handle string data, which is a sequence of characters, and perform a wide range of operations such as searching, sorting, comparing, matching and transforming strings. The primary goal of these algorithms is to optimize string operations by reducing the computational complexity and improving the efficiency of various string-related tasks. GSA plays a significant role in various computer science domains, including natural language processing, pattern recognition, data compression and cryptography. Some of the most common GSA include pattern matching algorithms (e.g., Knuth-Morris-Pratt, Boyer-Moore), sorting algorithms (e.g., Radix Sort, Bucket Sort), and text compression algorithms (e.g., Huffman coding, Lempel-Ziv-Welch). These algorithms have diverse applications, such as search engines using pattern matching algorithms to find relevant results or data compression algorithms being used to reduce the size of data for storage or transmission. Additionally, GSA can be used to analyze and manipulate text-based data in various programming languages, making it an essential tool for software developers and data scientists. By utilizing these algorithms, users can efficiently perform tasks involving string data and improve the overall performance of their applications.
using System;

namespace Algorithms.Strings
{
    /// <summary>
    /// Implements simple algorithms on strings.
    /// </summary>
    public static class GeneralStringAlgorithms
    {
        /// <summary>
        /// Finds character that creates longest consecutive substring with single character.
        /// </summary>
        /// <param name="input">String to find in.</param>
        /// <returns>Tuple containing char and number of times it appeared in a row.</returns>
        public static Tuple<char, int> FindLongestConsecutiveCharacters(string input)
        {
            var maxChar = input[0];

            var max = 1;
            var current = 1;

            for (var i = 1; i < input.Length; i++)
            {
                if (input[i] == input[i - 1])
                {
                    current++;
                    if (current > max)
                    {
                        max = current;
                        maxChar = input[i];
                    }
                }
                else
                {
                    current = 1;
                }
            }

            return new Tuple<char, int>(maxChar, max);
        }
    }
}

LANGUAGE:

DARK MODE: