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



how can i return string by vilating duplicates(inpyt like asdfsda but output should be 2a2d2sf and..

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

how can i return string by vilating duplicates(inpyt like asdfsda but output should be 2a2d2sf and..

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

Post New Answer

More C Sharp Interview Questions

What is string empty?

0 Answers  


Can we override static class in c#?

0 Answers  


What is a multi line comment?

0 Answers  


Explain inheritance in c#?

0 Answers  


Why is ienumerable used?

0 Answers  






What are the differences between static, public and void in c#?

0 Answers  


Explain attributes in c#?

0 Answers  


Method1() { int a=0, b=0, c=0; Monitor.Enter(this) c = 12; b = 3; a = c/b Moniter.Exit(this) } Method1() { int a=0, b=0, c=0; c = 12; b = 3; lock(this){ a = c/b } } Choose correct answer. a. Upon completion, Method1 and Method2 release the lock b. Upon Comletion, Method1 release the lcok and Method2 not. c. Upon Completion, Method2 release the lock and Method1 not. d. Upon Completion, neither Method1 or Method to release the lock.

1 Answers  


I want to print "Hello" even before main() is executed. How will you achieve that?

0 Answers   DELL,


What is data reader in c#?

0 Answers  


What is void method?

0 Answers  


What is an interface class? Give one example of it

0 Answers  


Categories