HSS
BAN USER1. First locate the kth node from start and end.
a. To find the kth node from last - take two pointers pointing to head. Move 1 pointer till kth position. Then move both the pointers together till the first pointer meets the last position. At this time 2nd pointer will be pointing to the kth node from last.
b. To find the kth node from first - Move a pointer to kth position by following link k-1 times.
2. Swap the nodes.
Do a merge sort.... It will take O(nlogn)
Then traverse along...
Before doing sorting tag each entry as exit and entry time.
While traversing For each entry add 1 and for each exit subtract 1. You will get your answer.
example:
entry time exit time
09:12:23 10:14:35
10:34:01 13:23:40
10:34:31 11:20:10
After Sorting:
09:12:23(entry)
10:14:35(exit)
10:34:01(entry)
10:34:31(entry)
11:20:10(exit)
13:23:40(exit)
So at any time e.g at 11:00:00 the number of persons will be :
+1
-1
+1
+1
= 2
char cal_max_occur(char str[])
- HSS March 26, 2013{
int hashArr[256]={0};
char MaxChar = str[0];
for (int i = 0; str[i] != '\0'; i++)
{
hashArr[int(str[i])]++;
if(hashArr[int(MaxChar)] < hashArr[int(str[i])])
MaxChar = str[i];
}
return MaxChar;
}