C Implementation
Approach\n Describe your approach to solving the problem. \nWe initialize an array charIndexMap to store the most recent index of each character encountered. We
# Approach\n<!-- Describe your approach to solving the problem. -->\nWe initialize an array charIndexMap to store the most recent index of each character encountered. We use a size of 256 assuming ASCII characters and initialize all elements to -1.\nWe iterate through the characters of the input string s.\nIf a character is already in the charIndexMap and its index is greater than or equal to the startIndex, we update the startIndex to the index after the last occurrence of the character.\nWe update the index of the current character in the charIndexMap.\nWe update maxLength if the length of the current substring is longer than the previous longest substring.\nFinally, we return maxLength as the result.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ \n\n# Code\n```\nint lengthOfLongestSubstring(char* s) {\n    if (!s || !*s) // Check if the string is empty\n        return 0;\n    \n    int charIndexMap[256]; // Assuming ASCII characters\n    memset(charIndexMap, -1, sizeof(charIndexMap)); // Initialize array with -1\n    \n    int maxLength = 0;\n    int startIndex = 0;\n    int i;\n    \n    for (i = 0; s[i] != \'\\0\'; i++) {\n        // If the character is already in the map and its index is after the start index of the current substring,\n        // update the start index to the index after the last occurrence of the character\n        if (charIndexMap[s[i]] != -1 && charIndexMap[s[i]] >= startIndex) {\n            startIndex = charIndexMap[s[i]] + 1;\n        }\n        \n        // Update the index of the current character\n        charIndexMap[s[i]] = i;\n        \n        // Update the maximum length if the current substring is longer\n        if (i - startIndex + 1 > maxLength) {\n            maxLength = i - startIndex + 1;\n        }\n    }\n    \n    return maxLength;\n}\n```
['C']