richa.shrma.iitd
BAN USER- 0of 0 votes
AnswersGiven a number. And one permutation of that number. Find out in how many steps can you get back to the original number from the permutation if you use the same mapping again and again. If its not possible, then state so.
- richa.shrma.iitd in United States
Example: 2315 -> 5213
So in this example Mapping is number at 1st index -> 2nd index
2nd index -> 4th index
3rd index -> 3rd index
4th index -> 1st index
So using same mapping can we come back to 2315. If yes then in how many steps?| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answersconsider binary representation of all numbers
- richa.shrma.iitd in United States
1 : 1
2 : 10
3 : 11
.
.
.
7 : 1 1 1
...
how many ones are requred to write numbers from 1 to n.
eg how many 1's are needed to write numbers from 1 to 7 : 12
expected complexity : logn| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
AnswersGiven a string. Tell its rank among all its permutations sorted lexicographically
- richa.shrma.iitd in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answerspow(a,b) = a*a*a ...*a (b times)
- richa.shrma.iitd in United States
consider pow(2,i)*pow(3,j) * pow(5,k)
where i,j,k are whole numbers.
so the possible numbers that can be written in this format are
1,2,3,4,5,6,8,9,10 ....
quesiton was to print nth number in this series (say 100th)
expected complexity : O(n).| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm - 0of 0 votes
Answersreverse a doubly link list without swapping pointers
- richa.shrma.iitd in India| Report Duplicate | Flag | PURGE
Komli Media Software Engineer / Developer Algorithm - 0of 0 votes
AnswersReverse a string in O(n) with recursion
- richa.shrma.iitd in India| Report Duplicate | Flag | PURGE
Komli Media Software Engineer / Developer Algorithm
(1000 + rand()%2000 ) / 1000
can do it more better by taking 10000000 instead of 1000, depend upon upto how much precision interviewer wants
just a variation of find minimum window which contains all characters ofa string
- richa.shrma.iitd April 12, 2012Final list should be sorted , so better is to break list into two parts one containing all even nodes and one containing all odd nodes.
then, reverse the list containing even nodes.
Then merge the both sorted lists in O(n) inplace.
make it num += num*10 + str[i] - '0';. for positive and negative you can use flag and make the return value positive and negative depending upon that
- richa.shrma.iitd April 02, 2012void reverse (char *s , int i, int j) {
if(i<j){
swap(s[i],s[j]);
reverse(s,i+1,j-1);
}
}
Use order stastistics , at every node left count is given
- richa.shrma.iitd March 25, 2012
[link]lmgtfy.com/?q=careercup.com%3Aimplement+a+stack+with+single+queue[/link]
- richa.shrma.iitd April 19, 2012Try it before you post a question here