By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,294 Members | 2,517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,294 IT Pros & Developers. It's quick & easy.

Finding subset of integers

P: 1
Can anyone write a code for this?

Searching a set of Integers

You are given two sets of integers. S1 and S2. The size of S1 is less than sizeof S2, i.e. the number of integers in S1 is less than the number of integers in S2.
Neither S1, not S2 can be an empty set.

You have to find out whether the sequence of integers of S1 is there in S2.

e.g. S1 = { 1, 5, 6 }, and S2 = { 4, 7, 9, 1, 5, 6 }.

Here, you have found the S1 in S2 subset.

S1 = { 1, 9 }, and S2 = {5, 8, 9 , 1 }
Here, S1 is not found in S2

S1 = { 2, 5 }, and S2 = {6, 2, 5, 7, 2, 5, 1 }
Here, S1 is found in S2, twice. You need to return all the instances.



You can do this in C/C++
Apr 27 '06 #1
Share this Question
Share on Google+
1 Reply


P: 5
convert the set into a string using some non-numeric delimeters
e.g 2#5 6#2#5

now find the occurences using substr()
May 4 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.