mp
BAN USERIf we are allowed to use a method that given a date converts it into number of seconds from Jan 1 1970.
And then consider a month as 4 weeks = 28 days and just check if the difference between the dates in 28 days?
If we need to be strict abt 30,31,28 write up some if statements...
Node and arc are same as in vipin's solution
But I would define Graph differently
class Graph
{
private:
struct Node *startNode;
public:
Graph():startNode(NULL){ }
struct Node *addNode();
struct arc *addArc();
void traverseGraph();
void deleteNode();
void deleteArc();
void populateNode(struct Node *); // link node with the archs it is pointing too.
};
- Maintain 4 pointers ptr to head of not selected list, pointer to curr in not selected, pointer to head of selected and pointer to current element of selected.
traverse through the list and modify linked list based on selected or not.
Difference from the previous post is that at any given point the definition of the new structure holds.
-- for non selected its a tranversal using next pointer.
-- For selected traverse using child pointer
If there is no circular cut off, since there is a pointer to the header of selected, we can still use child pointer
int reverse = original;
reverse = (reverse>>16) | (reverse<<16)
reverse = (reverse>>8 & x00FF00FF) | (reverse<<8 & xFF00FF00)
reverse = (reverse>>4 & x0F0F0F0F) | (reverse<<4 & x0F0F0F0F)
reverse = (reverse>>2 & x33333333) | (reverse<<2 & x33333333)
reverse = (reverse>>1 & x55555555) | (reverse<<1 & x11111111)
if(reverse == original) printf( "Palindrome" );
else printf ("Not Palindrome");
From the above example
- mp January 13, 20082,3,1,4,5,6,7,7 the sum is 35
but the sum is 35 even for 2,3,1,4,5,6,6,8.. and the repeated
number is 6!
How does just getting the sum help in finding the repeated number?
So, I think Hash which takes O(1) and extra space is the best solution
Second best is to sort and scan the sorted array O(nlogn)