adarsh
BAN USER- 0of 0 votes
AnswersAmazon telliphonic 17 May, 2012
- adarsh in India
1.) There is a sequence where aphabets are written like this..
a,b,c,d,.......,x,y,z,aa,ab,ac........,az,ba,bb,bc,bd......bz,ca,cb.........cz........,aaa,aab,aac.....aaz,............zzz,aaaa...........zzzz..... and so on..
WAP to find out the string value at kth position.
like if k= 28 the string on 28 will be "ab".| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Data Structures
int * getMergedArray(int a[],int N ) {
/*N: size of the array */
if (N <= 6)
return NULL;
int* a1 = a;
int* a2 = a + (N / 3);
int* a3 = a + (2 * (N / 3 ));
int* result = (int*) malloc (N * sizeof(int));
int i = 0;
for (; i < N;)
{
if (!a1 || !a2 || !a3)
{
break;
}
result[i++] = *a1;
result[i++] = *a2;
result[i++] = *a3;
a1 = a1++;
a2 = a2++;
a3 = a3++;
}
if (i < N)
{
for (int j=i;j < N;j++)
{
result[j] = a[j];
}
}
if (result)
{
return result;
}
}
it's like "aditya and aditi ......" so "adit" is prefix for 2 words and having length 4. So we need to find out the max length of prefix among all the words in the complete string.
- adarsh May 18, 2012