Given two strings like x=?hello? and y=?open?, remove any
character from string x which is also used in string y,
thus making the result x=?hll?.

Answer Posted / skybeaver

static public string StupidQuestion(string x, string y)
{
StringBuilder sb = new StringBuilder();
Hashtable ht = new Hashtable();

// just one pass through y
foreach( char c in y.ToCharArray() )
if( !ht.Contains(c) )
ht.Add(c, c)

// just one pass thru x
foreach( char c in x.ToCharArray() )
if( !ht.Contains(c) )
sb.Append(c);

return sb.ToString();
}

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is purpose of inheritance?

641


Why do we use class in oops?

551


what is different between oops and c++

1998


What is protected in oop?

598


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

1635






Why is abstraction needed?

561


What is difference between inheritance and polymorphism?

561


Templates mean

1585


what are the realtime excercises in C++?

2331


What is polymorphism in oop example?

511


Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.

2002


write a program that takes input in digits and display the result in words from 1 to 1000

1982


What is an interface in oop?

591


What are two types of polymorphism?

607


What is abstraction in oop?

626