bhajatin
BAN USERIts easy, you just store the XOR of the previous pointer and the next pointer in the pointer part of the LinkedList Node and then just extract the Node's next pointer or the previous pointer whenever required by using one of the prev/next pointers. You keep doing this and storing the XOR instead of just the next pointer and you can reverse the linked list using only one pointer.
- bhajatin November 02, 2013Solution 1 ) Use a bit vector to mark off areas covered in the set, display the areas with set bits in the end ( very little memory used, output is O(n).
Solution 2 ) traverse the given sets just once and keep adding the disjoint sets to the output set while also checking the ranges for the already present sets in the output set so as to increase the range if the sets overlap etc
For this problem, why can't we just put all the characters of the string into a SET and then try to put the characters of the second string into the set. If the SET already contains the character, we should remove it. In the end, if the set is empty, we know its an anagram :). This o(n) solution
- bhajatin November 07, 2013