0
How can I compare the n-1 elements of two Sets ?
The algorithm I want is one which take two SortedSet in argument, if their size is equal and if their n-1 element are identical, then we merge them. https://code.sololearn.com/cTjYUZgWci6w/?ref=app
9 Answers
+ 2
In the same code before returning the merged set you can store it inside another SortedSet and check if the size returned is equal to (set1.size()+set2.size() -1). If that is equal then you can return the merged set otherwise return null.
Edit: Adrien Linares You must store that equation value before merging.
+ 1
What type is BooleanVariable here?
+ 1
This code should work exactly for the conditions you have provided.
I have done it for strings but the approach would be the same for all types.
https://code.sololearn.com/ccmH2o9LXMQB/?ref=app
+ 1
Is that working?
0
Avinesh It is a class which which take in parameter a String
0
It looks good thank you! there's a last condition, it's that the n other elements are different
0
Btw I also thought to convert the set into list
0
Avinesh these three conditions otherwise we return null
0
Okey I modified it, is it good now?