Comments on: Longest substring of unique characters https://demo.ritambhara.in/longest-substring-of-unique-characters/ Coding / System Design Interviews Mon, 04 Feb 2013 10:59:43 +0000 hourly 1 https://wordpress.org/?v=6.7.2 By: Muhammad Tahir https://demo.ritambhara.in/longest-substring-of-unique-characters/#comment-1837 Mon, 04 Feb 2013 10:59:43 +0000 http://www.ritambhara.in/?p=1689#comment-1837 I want to change this code according to my excercise
what is the longest substring of characters strictly rising (the following is greater (>) of the previous)for example abcdghijabcdefghij so strictly rising is abcdefghij
what is the longest substring of successive characters (i.e.: fhkjshdfruytyzABCDEfglsj => 7) ABCDEfgl
please someone reply me with changes
#include
#include
#include
#include
#include
main(){
int longestUniqueSubstring(char *str)
{
if(str == NULL)
return -1;
int currentLen = 0;
int maxLen = 0;
int lastSeen[256];
for(int i=0; i<256; i++)
lastSeen[i] = -1;
int n = strlen(str);
for (int i = 0; i lastSeen[str[i]])
{
currentLen++;
}
else
{
if (currentLen > maxLen)
maxLen = currentLen;
currentLen = i – lastSeen[str[i]];
}
// Updating Last Seen for current character
lastSeen[str[i]] = i;
}
// In case the longest substring is at end
if (currentLen > maxLen)
maxLen = currentLen;
return maxLen;
}
}

]]>