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)](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f547e02da27_75166f547dfb4323.jpg)
#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
Get step-by-step solutions from verified subject matter experts
