Tag: Tricky

Print all distinct Subsets of a given Set

Given a set S, generate all distinct subsets of it i.e., find distinct power set of set S. A power set of any set S is the set of all subsets of S, including the empty set and S itself.  

Single line expressions to swap two integers in Java

Given two integers, swap them in single line in Java.     There are many expressions to swap two variables in single line in Java. Notice that all below methods can also be used with C/C++.   1. Using Bitwise XOR(^) Operator  

Download   Run Code   2. Using Addition and Subtraction Operator …