0ms Runtime using C Programming Language with Easy String Operations
IntuitionThe problem revolves around transforming a string of digits into a sequence of pairs, repeatedly reducing the length of the string until only two digit
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem revolves around transforming a string of digits into a sequence of pairs, repeatedly reducing the length of the string until only two digits remain. The main focus is to compute the new digits as the modulo 10 of the sum of consecutive pairs. Once the string is reduced, we check if the final two digits are the same.

# Approach
<!-- Describe your approach to solving the problem. -->
Start with a string s consisting of digits.
Use a loop to repeatedly reduce the string until it has exactly two digits:
For each iteration, calculate the new sequence of digits by summing consecutive digits and taking the result modulo 10.
Replace the old string with the new sequence after computation.
Once the string contains exactly two digits, check if they are the same and return true if they are, or false otherwise.
Memory management is crucial to handle intermediate strings efficiently.

![Screenshot 2025-03-15 105849.png](https://assets.leetcode.com/users/images/360028a4-d629-4460-bd92-b9425257c6ea_1742016686.1712515.png)

# Complexity
- Time complexity: O(n2)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```c []
#include <string.h>
bool hasSameDigits(char* s) {
    while (strlen(s) > 2) {
        int n = strlen(s);
        char* new_s = (char*)malloc(n * sizeof(char)); // To store the new sequence
        int k = 0;
        for (int i = 0; i < n - 1; i++) {
            new_s[k++] =
                ((s[i] - '0') + (s[i + 1] - '0')) % 10 + '0'; // Sum modulo 10
        }
        new_s[k] = '\0'; // Null-terminate the string
        strcpy(s, new_s);
        free(new_s);
    }
    return s[0] == s[1];
}
```
['C']