60 487
Assignments Done
98,1%
Successfully Done
In April 2018

# Answer to Question #44994 in C for Palak

Question #44994
A string is said to be &quot;Beautiful&quot;, if it contains only non repetitive alphabets. Let S be the string with lower case alphabets, your task is to find out the longest &quot;Beautiful sub-string&quot; present in the given string S.

Input Format:

First line starts with T, which is the number of test cases. Each test case contains string S.

Output Format:

Print the first longest beautiful sub string present in the string S.

Constraints:
1&lt;=T&lt;=10

1&lt;=|S|&lt;=5500, S will contain only lower case alphabets.

Sample Input and Output

SNo. Input Output
1
2
ss
abcdeddd

s
abcde
//Answer on Question#44994 - Progamming - C#include &lt;stdio.h&gt;#include &lt;string.h&gt;int main() {   int T;   char S[70];   int len;   int i, j;   int curr;   int start, finish;   int pos[&#039;z&#039; - &#039;a&#039; + 1];   scanf(&quot;%d&quot;, &amp;T);   while (T-- &gt; 0) {      scanf(&quot;%s&quot;, S);      len = strlen(S);      start = 0;&nbsp;      finish = 0;      curr = 0;      memset(pos, -1, sizeof(pos));      for (i = 0; i &lt; len; ++i) {         if (pos[S[i] - &#039;a&#039;] != -1) {            if (i - curr &gt; finish - start + 1) {               start = curr;               finish = i - 1;            }            for (j = curr; j &lt; pos[S[i] - &#039;a&#039;]; ++j) {               pos[S[j] - &#039;a&#039;] = -1;            }&nbsp;            curr = pos[S[i] - &#039;a&#039;] + 1;         } else {            pos[S[i] - &#039;a&#039;] = i;         }      }            if (len - curr &gt; finish - start + 1) {         start = curr;         finish = len - 1;      }      for (i = start; i &lt;= finish; ++i) {         printf(&quot;%c&quot;, S[i]);      }      printf(&quot;\n&quot;);   }}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!