chlam98
BAN USER
Comments (4)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Generally speaking, BST needs N * (space of node) where N is number of node. However, HashTable( linear probing or chaining mechanism) needs more than N * (space of node) space to achieve a better performance, otherwise there will be too many collisions. So, overall, I will vote for BST for space efficiency at this case.
- chlam98 July 03, 2013Comment hidden because of low score. Click to expand.
0
of 0 vote
The idea is to change the string into base-26 system. The pseudo code as follows:
int sum(String str)
{
//First check the str is monotonic increasing.
if( str is not increasing ) return -1;
int sum = 0;
int length = str.length;
for(int i = 0; i < length; i++) {
//assuming all letters are in lower case.
sum += (26 ^ ( length - i - 1) ) * ( (str[i] - 'a') + 1);
}
return sum;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
You are right, I overlooked view examples and took it as 26-based system, thanks
- chlam98 July 03, 2013