bibbsey
BAN USER1. Check if the lengths are same. If so, continue to step 2, else return false.
2. Insert each character of first string into std::set<char>. This is C++ specific. Other languages might be having counterpart of set.
3. Iterate through each character of second string and do a std::set::find on the set created in step 2.
4. If std::set::find returns std::set::end at any time during iteration, then result is false and break the loop. Else return true.
Complexity nlogn
Use a static variable in the linked list structure.
struct LL
{
int data;
LL* next;
static LL* secondLast;
};
While creating the list, keep updating the static variable so that it points the second last one.
Then it's simple
delete LL::secondLast->next;
LL::secondLast->next = NULL;
oopsie... correct.
- bibbsey August 08, 2013In that case, instead of find, we can do an erase. If erase returns "not found" error then it's not an anagram. And set does not allow duplicates. In order to support your example, we have to use multi set. Still complexity remains nlogn