DashDash
BAN USER
- -2of 2 votes
AnswersHow to print a variable 1000 times without using loops and recurssion
- DashDash in India| Report Duplicate | Flag | PURGE
Software Engineer / Developer - 0of 0 votes
AnswersWe have
- DashDash in India for Development
char *p = "abc";
I know we cant do p[0] = 'a'. What is the reason behind it?| Report Duplicate | Flag | PURGE
Software Engineer / Developer C++ - 0of 0 votes
AnswersWhat is the next number in the series
- DashDash in India
2,4,8,16,24...| Report Duplicate | Flag | PURGE
Goldman Sachs Applications Developer Brain Teasers - 0of 0 votes
Answersvoid copystring(char* dest, char *source)
- DashDash
{
while(*source != NULL)
{
*dest = *source;
dest++;
source++;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char input[10] = "hello";
char *dest;
dest = &input[1];
copystring(dest, input);
return 0;
}
What is the output of the program...| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer C++
I will take an example to ilustrate
30 !
- take a ctr and increment by 1 since 30 has 1 0
- 29 reject this
- 28 it has 2's 2 and one 9 take a var for count of even
- 27 leave
- 26 1 2 increment even num count
- 25 it has 2 five take in another var
Hence at last number of 0 will be
Var for 0 + min(var if 2 , var of 5)
Use a queue of length 10. And a hash table with key value
The hash will have the key and the corresponding element number in the queue
The value will be stored at the element number in the queue.
Put will check if key exists will remove that element from queue and add it to last. If length 10 the will remove first element remove its key from hash and add that element in the last
Do a level order traversal. Remember for null leaves enter blank in an array
eg
1
2 3
4 6 7
post order traversal is : 1234_67
Now here we follow the property that child will always be at 2i and 2i+1 index or vise versa parent is always at |i/2| index
therefore parent of 1 will be no one
parent of 2 = 2/2 = 1 i.e 1
parent of 3 = 3/2 = 1 i.e 1
parent of 4 = 4/2 = 2 i.e 2 and rest copy from 2
parent of 6 = 6/2 = 3 i.e 3 and rest copy from 3
parent of 7 = 7/2 = 3 i.e 3 and rest copy from 3
This can be solved using recursion
Please let me know if I have messed up somewhere here.
void FromTo(char *source, char *dest, char **stackofWords, int wordCount)
{
if(strcomp(source, dest) == 0)
{
print(stackofWords, wordcount);
return;
}
else
{
for(int i=0;i<strlen(source);i++)
{
for(int j=0;j<26;j++)
{
if((char)((int)'A' + j) != source[i])
source[i] = (char)((int)'A' + j);
else
continue;
stackofwords[wordcount] = source;
Fromto(source, dest, stackofWords, wordcount+1);
}
}
}
}
Algo
I am changing every letter with all the alphabets in the english dictionary and then comparing with the desitnation.
Here is my question
We can an array of bits. When we convert it to a integer, isn't we are scanning each and every array element? I mean
We divide the array into 2 halfes and take the first half. Now to know whether first half has a 1 we convert the array into integer.
My question is how we are converting the array into integer?Are we not scanning the complete array for this?
Do you want me to code for the solution? I think once an algorithm of a problem is known, coding may no be a problem.
Please do let me know if you are finding anything wrong with the above solution, we can discuss.
Also let me know if you want concrete code, I will write it down for you
A tree just like it is done in any xml library
- DashDash January 14, 2015