A program that will get an input string and provide the possible unique substrings of that string.
Ususally when a programmer goes to the interview, the company asks to write the code of some program to check your logic and coding abilities.
You can write the code in any language like C, C++, Java, C# and so on. There is no barrier to the language and technology because the company wants to check your ability to think and your skills to write the code.
Some companies only want the algorithm to check your skills.
One of the programs in those common programs is the following.
Example
Input = ”abcde”
Output = a, ab, abc, abcd, abcde, b, bc, bcd, bcde, c, cd, cde, d, de, e
Input = ”hello”
Output = h, he, hel, hell, hello, e, el, ell, ello, l, ll, llo, lo, o
Input = ” abab”
Output = a, ab, aba, abab, b, ba, bab
To do this, I will use the Visual Studio 2012 as an IDE and C# as a language,
Create a new console application named "ConsoleApplication1".

Where you will get the page that will look like:
Now I will write the code in some steps.
Get the input string from the user.
- Console.Write("Eneter the input String:");
- //Get the string from the user and save it in a variable
- string input = Console.ReadLine();

Write the code in a function to get all the possible unique substrings from the input string.
- public static void PossibleUniqueSubString(string input)
- {
- //declare the string variable
- string final = "";
- //Get a string of possible substrings with out uniqueness
- for (int i = 0; i < input.Length; i++)
- {
- string str = "";
- for (int j = i; j < input.Length; j++)
- {
- str += input[j];
- final += str + ",";
- }
- }
- //Remove the ending comma from the string
- final = final.Remove(final.Length - 1, 1);
- //Get an array after Spilt the string on basis of comma
- string[] arr = final.Split(',');
- //Get the distinct array
- arr = arr.Distinct().ToArray();
- //Print the array
- for (int i = 0; i < arr.Length; i++)
- Console.Write(arr[i]+" ");
- }
- Console.Write("Eneter the input String:");
- //Get the string from the user and save it in a variable
- string input = Console.ReadLine();
- PossibleUniqueSubString(input);
a, ab, abc, abcd, abcde, b, bc, bcd, bcde, c, cd, cde, d, de, e

If I provide ”hello” as an input string then the output will be like:
h, he, hel, hell, hello, e, el, ell, ello, l, ll, llo, lo, o

If I provide ”abab” as an input string then the output will be like:
a, ab, aba, abab, b, ba, bab


Karthik Muthu KaruppanPosted Mar 30, 2015, 11:24 AM
good one
Gowtham RajamanickamPosted Mar 28, 2015, 12:26 PM
great one..
Nanhe SiddiquePosted Mar 27, 2015, 11:54 PM
nice
Khargesh RajputPosted Mar 27, 2015, 10:25 PM
Nice thanks for sharing
RakeshPosted Mar 27, 2015, 5:35 PM
Great..It's asked in many interview, thanks for sharing