Question: #include #include int strlength(char str[], int length, int *first, int *last) { char curr_char = str[0]; int start=0;; int finish=0; int curr_start=0; int max_length =

 #include #include int strlength(char str[], int length, int *first, int *last)

#include  #include  int strlength(char str[], int length, int *first, int *last) { char curr_char = str[0]; int start=0;; int finish=0; int curr_start=0; int max_length = 1; for (int i=0; i max_length) { max_length = curr_length; start = curr_start; finish = i; } } else { curr_char = str[i]; curr_start = i; } } *first = start; *last = finish; return max_length; } void main(int argc, char *argv[]) { int first, last; char str1[30]="pqrpqrpqrpqrtttrrttrrrttpqrpqr"; int n = strlength(str1, 30, &first, &last); printf("String 1 = %s ",str1); printf("String length = %d, first = %d, last = %d ", n, first, last); char str2[21]="abcbbcabbabbabcbbcbca"; n = strlength(str2, 21, &first, &last); printf("String 2 = %s ",str2); printf("String length = %d, first = %d, last = %d ", n, first, last); }

Problem 4 [1 pt]. This problem is a coding problem, unrelated to probability, but good practice for algorithm design. Attached is a program strlength.c, and it has a function int strlength(char str[ ], int length, int * first, int *last) /* 'length' is the length of string str[ ]) */ that - Returns the length of the longest substring of str[ ] of a single character - Sets "first" and "last" as the indices where the substring starts and ends For example, aaabaabbababbbba has the longest substring bbbb which has length 4, and starts at position 11 and ends at position 14. Modify the function strlength(), so that it finds the longest substring with at most two distinct characters. For example

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!