Repository: TheAlgorithms/C-Plus-Plus
File: dynamic_programming/longest_common_string.cpp (C++)

Code before:
/**
 * @file
 * @brief contains the definition of the function longest_common_string_length
 * @details
 * the function longest_common_string_length computes the length
 * of the longest common string which can be created of two input strings
 * by removing characters from them
 */

#include <cassert>  /// for assert
#include <string>   /// for std::string
#include <utility>  /// for std::move
#include <vector>   /// for std::vector

/**
 * @brief computes the length of the longest common string created from input
 * strings
 * @details has O(str_a.size()*str_b.size()) time and memory complexity
 * @param string_a first input string
 * @param string_b second input string
 * @returns the length of the longest common string which can be strated from
 * str_a and str_b
 */
std::size_t longest_common_string_length(const std::string& string_a,
                                         const std::string& string_b) {
    const auto size_a = string_a.size();
    const auto size_b = string_b.size();
    std::vector<std::vector<std::size_t>> sub_sols(
        size_a + 1, std::vector<std::size_t>(size_b + 1, 0));

    const auto limit = static_cast<std::size_t>(-1);
    for (std::size_t pos_a = size_a - 1; pos_a != limit; --pos_a) {
        for (std::size_t pos_b = size_b - 1; pos_b != limit; --pos_b) {
            if (string_a[pos_a] == string_b[pos_b]) {
                sub_sols[pos_a][pos_b] = 1 + sub_sols[pos_a + 1][pos_b + 1];
            } else {
                sub_sols[pos_a][pos_b] = std::max(sub_sols[pos_a + 1][pos_b],
                                                  sub_sols[pos_a][pos_b + 1]);

Review comment (refactor):
```suggestion
#include <cassert>     /// for assert
#include <string>      /// for std::string
#include <utility>     /// for std::move
#include <vector>      /// for std::vector
#include <iostream>  /// for IO operations
```


Code after:
/**
 * @file
 * @brief contains the definition of the function ::longest_common_string_length
 * @details
 * the function ::longest_common_string_length computes the length
 * of the longest common string which can be created of two input strings
 * by removing characters from them
 *
 * @author [Nikhil Arora](https://github.com/nikhilarora068)
 * @author [Piotr Idzik](https://github.com/vil02)
 */

#include <cassert>   /// for assert
#include <iostream>  /// for std::cout
#include <string>    /// for std::string
#include <utility>   /// for std::move
#include <vector>    /// for std::vector

/**
 * @brief computes the length of the longest common string created from input
 * strings
 * @details has O(str_a.size()*str_b.size()) time and memory complexity
 * @param string_a first input string
 * @param string_b second input string
 * @returns the length of the longest common string which can be strated from
 * str_a and str_b
 */
std::size_t longest_common_string_length(const std::string& string_a,
                                         const std::string& string_b) {
    const auto size_a = string_a.size();
    const auto size_b = string_b.size();
    std::vector<std::vector<std::size_t>> sub_sols(
        size_a + 1, std::vector<std::size_t>(size_b + 1, 0));

    const auto limit = static_cast<std::size_t>(-1);
    for (std::size_t pos_a = size_a - 1; pos_a != limit; --pos_a) {
        for (std::size_t pos_b = size_b - 1; pos_b != limit; --pos_b) {
            if (string_a[pos_a] == string_b[pos_b]) {