gagdeep
BAN USERMy Previous answer will only return second highest record... More general solution is...
select a.sal from salary a where "N" = (select count(distinct b.sal) from salary b where a.sal <= b.sal)
Change N to 2 to get second highest... change it to 3 to get 3rd highest and so on.
Keep a current pointer on the second element a(1). place two other pointers at current-1 and current+1. check if curr-1 and curr+1 are equal. then move current pointer ahead. again set curr-1 and curr1 and check for:
If curr is at ith position:
while(i>0)
{
if (curr-1 == curr+1)
{
(curr+1)++;
(curr-1)--;
i--;
}
else break;
}
keep tack of the largest one by storing the value of current for which the length of palindrome was max. also keep track of it's length for each i. Then u can print the longest palindrome.
Static and global variable differ a lot in their behaviour to life and scope. First, let me distinguish between life and scope. Life of an object determines whether the object is still in the memory (of the process) whereas scope of the object is whether can I know the variable by its name at this position. It is possible that object is live, but not visible (not in scope) but not that object is not alive but in scope (except for dynamically allocated objects where you refer object through pointers).
Static variables are local in scope to their module in which they are defined, but life is throughout the program. Say for a static variable inside a function cannot be called from outside the function (because it's not in scope) but is alive and exists in memory. The next time this function is entered (within the same program) the same chunk of memory would be accessed now retaining the variables old value and no new memory is allocated this time for this variable like other variables in the function (automatic variables). So basically the variable persists throughout the program. Similarly if a static variable is defined in a global space (say at beginning of file) then this variable will be
accessible only in this file (file scope).
change select a.sal from sa... to select * from sa...
- gagdeep November 27, 2009I was testing it so forgot to change to *