how can i return string by vilating duplicates(inpyt like
asdfsda but output should be 2a2d2sf and 2a,2d,2s,f)
Answers were Sorted based on User's Feedback
Answer / adityakiran
I suppose this question is intended to test the knowledge on
IEnumerator. The following piece of code may give the
required first part of the output...
string x = "asdfsdaaasasa";
string output = "";
int count = 0;
IEnumerator ie = x.GetEnumerator();
IEnumerator iee = x.GetEnumerator();
while(ie.MoveNext())
{
while(iee.MoveNext())
{
if ((char)ie.Current == (char)iee.Current)
{
count++;
}
}
iee.Reset();
if (!output.Contains(ie.Current.ToString()))
output = output + count + ie.Current;
count = 0;
}
Console.WriteLine(output);
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / hari
we can modify the previous answer to make it efficient...
check it..
string x = "asdfsdaaasasa";
string output = "";
int count = 0;
IEnumerator ie = x.GetEnumerator();
IEnumerator iee = x.GetEnumerator();
while(ie.MoveNext())
{
if (!output.Contains(ie.Current.ToString()))
{
while(iee.MoveNext())
{
if ((char)ie.Current == (char)iee.Current)
{
count++;
}
}
iee.Reset();
output = output + count + ie.Current;
count = 0;
}
}
Console.WriteLine(output);
Is This Answer Correct ? | 1 Yes | 0 No |
Can abstract class be sealed?
7.What are typed data set?
Why do we use lambda expression in c#?
State the top.NET class that everything is derived from?
Are c# objects passed by reference?
What are c# i/o classes? What are the commonly used i/o classes?
What is generic method in c#?
Where is the output of TextWriterTraceListener redirected?
How do you comment out code in c#?
What is the syntax for calling an overloaded constructor within a constructor (this() and constructorname() does not compile)?
Can hashtable have duplicate keys?
Can constructor be overloaded in c#?