Skip to main content

Amazon Campus Placement Test - 2015,HBTI Kanpur

This year in February, Amazon conducted  online test in our campus for campus recruitment. Here are the necessary information and details of the test.


The test conducted on the amazon official website. Test duration was one and half hours there were two sections in the question paper.There were no invigilator from amazon nevertheless the candidates were not suppose to do any kind of cheating like copying code from friend are use Internet. They told that they have some kind of mechanism to detect such kind of cheating.If they found any kind of unfairness in test they can ban your college or not willing to declare the result of the test so please don't try to do such kind of activities in the test.

Both section didn't had individual time so you can manage time from one section to another.The coding section is most important so you must solve at least one coding problem otherwise they will not even consider you.   

Section 1: In this section there were 20 multiple choice questions in which there were 2 or 3 questions of aptitude and logical reasoning, 4-5 question of operating system and rest of C, C++, DS, Algorithms.

Section 2: [CODING QUESTION] There were two coding question in this section and you have to write running code on their editor and submit the code.

Problem 1:
Given a arithmetic expression as string and you have to print the value of the expression.
For example:
Input: "5-3+9/4"
Output: 4 


Solution: The below code is postfix evaluation of infix expression without converting it into postfix expression.

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<bitset>
  4. #include<vector>
  5. #include<cmath>
  6. #include<queue>
  7. #include<map>
  8. #include<set>
  9. #include<list>
  10. #include<stack>
  11. #include<string>
  12. #include<cstdlib>
  13. #include<cstring>
  14. #include<algorithm>

  15. using namespace std;

  16. #define fori(i,n) for(i=0;i<(n);++i)
  17. #define forin(i,s,n) for(i=(s);i<=(n);++i)
  18. #define forn(i,n) for(i=(n-1);i>=0;--i)
  19. #define forni(i,n,e) for(i=(n);i>=(e);--i)
  20. #define MAX(a,  b) ((a) > (b) ? (a) : (b))
  21. #define MIN(a,  b) ((a) < (b) ? (a) : (b))
  22. #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
  23. #define SQ(X) ( (X) * (X) )
  24. #define nil NULL
  25. #define itr iterator
  26. #define pb push_back
  27. #define mod 1000000007 //10^9+7
  28. #define P printf
  29. #define S scanf
  30. //#define getchar getchar_unlocked  //Uncomment this if you are going to use fast i/o

  31. typedef long long int lli;
  32. typedef long double ld;
  33. typedef vector<int> vi;
  34. typedef vector<lli> vll;
  35. typedef pair<int,int> ii;

  36. /*------------------------------------------------------------------------------
  37. ++++++++++++++++++++++++++++++++Source Code+++++++++++++++++++++++++++++++++++++
  38. ------------------------------------------------------------------------------*/
  39. //Functions and Global variables
  40. void program();
  41. inline void pAry(int a[],int n)
  42. {
  43. int i;
  44. fori(i,n)
  45. printf("%d ",a[i]);
  46. printf("\n");
  47. }
  48. inline void pSAry(int a[],int s,int e)
  49. {
  50. int i;
  51. forin(i,s,e)
  52. printf("%d ",a[i]);
  53. printf("\n");
  54. }

  55. //int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
  56. //double pi=2*acos(0.0);
  57. stack<int> va_stk;
  58. queue<int> dg_q;
  59. stack<char> op_stk;
  60. map<char,int> p_map;

  61. int eval(char op)
  62. {
  63. if((int)va_stk.size() < 2)
  64. {   P("Given expression is not valid\n");
  65. return 0;
  66. }
  67. int o1,o2;
  68. o2= va_stk.top();
  69. va_stk.pop();
  70. o1=va_stk.top();
  71. va_stk.pop();
  72. switch(op)
  73. {
  74. case '+':
  75. return o1+o2;
  76. case '-':
  77. return o1-o2;
  78. case '*':
  79. return o1*o2;
  80. case '/':
  81. return o1/o2; //You can add more operator here if you need
  82. default:
  83. P("Undefined Operator\n");
  84. return 0;
  85. }
  86. }
  87. //Main()
  88. int main()
  89. {
  90.    //freopen("IN.txt", "r", stdin);
  91.   //freopen("OUT.txt", "w", stdout);
  92.   p_map['(']=0;
  93.   p_map['+']=1;
  94.   p_map['-']=1;
  95.   p_map['*']=2;
  96.   p_map['/']=2;
  97.   program();
  98.   return 0;
  99. }

  100. //Root Program
  101. void program()
  102. {
  103.    char s[100];
  104.    S("%s",s);
  105.    int i=0;
  106.    while(s[i]!=0)
  107.    {
  108.     if(s[i]>='0' && s[i]<='9')
  109.     {
  110.     dg_q.push(s[i]-'0');
  111.     }
  112.     else
  113.     {
  114.        //You have to take care extra if parenthesis  and exponent operator
  115. // present in expression
  116.    int var=0;
  117. while(!dg_q.empty())
  118. {
  119. var=10*var + dg_q.front();
  120. dg_q.pop();
  121. }
  122. va_stk.push(var);
  123. if(op_stk.empty())
  124. {
  125. op_stk.push(s[i]);
  126. }
  127. else
  128. {
  129. while((!op_stk.empty()) && (p_map[op_stk.top()] >= p_map[s[i]]))
  130. {
  131. int temp=eval(op_stk.top());
  132. va_stk.push(temp);
  133. op_stk.pop();
  134. }
  135. op_stk.push(s[i]);
  136. }
  137.     }
  138.     i++;
  139.    }
  140.    int var=0;
  141. while(!dg_q.empty())
  142. {
  143. var=10*var + dg_q.front();
  144. dg_q.pop();
  145. }
  146. va_stk.push(var);
  147. while(!op_stk.empty())
  148. {
  149. int temp=eval(op_stk.top());
  150. va_stk.push(temp);
  151. op_stk.pop();
  152. }
  153. int value=va_stk.top();
  154. va_stk.pop();
  155. if(va_stk.empty())
  156. {
  157. P("The value of expression is %d\n",value);
  158. }else
  159. {
  160. P("The give expression is not valid\n");
  161. }
  162.    
  163. }



Problem 2: 
Given a keypad as shown in diagram, and a n digit number, print all words in alphanumeric order which are possible by pressing these numbers.


For example if input number is 234, possible words which can be formed are (Alphabetical order):
adg adh adi aeg aeh aei afg afh afi bdg bdh bdi beg beh bei bfg bfh bfi cdg cdh cdi ceg ceh cei cfg cfh cfi

Solution: Below  code is implementation of  simple solution which comes first into mind.
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<bitset>
  4. #include<vector>
  5. #include<cmath>
  6. #include<queue>
  7. #include<map>
  8. #include<set>
  9. #include<list>
  10. #include<stack>
  11. #include<limits>
  12. #include<string>
  13. #include<cstdlib>
  14. #include<cstring>
  15. #include<algorithm>

  16. using namespace std;

  17. #define fori(i,s,n) for(i=(s);i<=(n);++i)
  18. #define forn(i,n,e) for(i=(n);i>=(e);--i)
  19. #define MAX(a,  b) ((a) > (b) ? (a) : (b))
  20. #define MIN(a,  b) ((a) < (b) ? (a) : (b))
  21. #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
  22. #define SQ(X) ( (X) * (X) )
  23. #define nil NULL
  24. #define itr iterator
  25. #define pb push_back
  26. #define mod 1000000007 //10^9+7
  27. #define P printf
  28. #define S scanf
  29. //#define getchar getchar_unlocked  //Uncomment this if you are going to use fast i/o

  30. typedef long long int lli;
  31. typedef long double ld;
  32. typedef vector<int> vi;
  33. typedef vector<lli> vll;
  34. typedef pair<int,int> ii;

  35. /*------------------------------------------------------------------------------
  36. ++++++++++++++++++++++++++++++++Source Code+++++++++++++++++++++++++++++++++++++
  37. ------------------------------------------------------------------------------*/
  38. //Functions and Global variables
  39. void program();

  40. inline void pAry(int a[],int s,int e)
  41. {
  42. int i;
  43. fori(i,s,e)
  44. printf("%d ",a[i]);
  45. printf("\n");
  46. }

  47. //int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
  48. //double pi=2*acos(0.0);

  49. //Main()
  50. int main()
  51. {
  52.    //freopen("IN.txt", "r", stdin);
  53.   //freopen("OUT.txt", "w", stdout);
  54.   program();
  55.   return 0;
  56. }

  57. //Root Program
  58. void program()
  59. {
  60. int n;
  61. S("%d",&n);
  62. int num[10];
  63. int i,num_size;
  64. //store the number into an array integer
  65. stack<int> stk;
  66. if(n==0)
  67. {
  68. num[0]=0;
  69. num_size=1;
  70. }
  71. else
  72. {
  73. while(n>0)
  74. {
  75. stk.push(n%10);
  76. n/=10;
  77. }
  78. i=0;
  79. while(!stk.empty())
  80. {
  81. num[i++]=stk.top();
  82. stk.pop();
  83. }
  84. num_size=i;
  85. }
  86. //pAry(num,0,num_size-1);
  87. int total,grand_total,block,j,k;
  88. const char hashTable[10][5] = {"", "", "abc", "def", "ghi", "jkl",
  89.                                "mno", "pqrs", "tuv", "wxyz"};
  90.                                
  91.     total=1;
  92.     fori(i,0,num_size-1)
  93.     {
  94.      total*=(strlen(hashTable[num[i]]));
  95.     }
  96.     cout<<"Total "<<total<<endl;
  97.     
  98.     grand_total=total;
  99.     
  100.     char table[grand_total+5][num_size+2];
  101.     
  102.     fori(i,0,num_size-1)
  103.     {
  104.      int idx=0;
  105.      int ws=strlen(hashTable[num[i]]);
  106.      block=total/ws;
  107.      fori(j,0,ws-1)
  108.      {
  109.      fori(k,0,block-1)
  110.      {
  111.      table[idx++][i]=hashTable[num[i]][j];
  112.      }
  113.      }
  114.     
  115.      while(idx<grand_total)
  116.      {
  117.      table[idx][i]=table[idx%total][i];
  118.      idx++;
  119.      }
  120.     
  121.      total=block;
  122.     }
  123.     
  124.     fori(i,0,grand_total-1)
  125.     {
  126.      table[i][num_size]='\0';
  127. cout<<table[i]<<endl;
  128.     }
  129.     
  130. }
For another approach you can visit the link http://www.geeksforgeeks.org/find-possible-words-phone-digits/



Note:- For any suggestion and query regarding this post please comment below.






Comments

  1. Comment By: victorious28 June 2015 at 05:58

    ReplyDelete
  2. using namespace std;

    map > m;
    void generate()
    {
    m[2].push_back('A');m[2].push_back('B');m[2].push_back('C');
    m[3].push_back('D');m[3].push_back('E');m[3].push_back('F');
    m[4].push_back('G');m[4].push_back('H');m[4].push_back('I');
    m[5].push_back('J');m[5].push_back('K');m[5].push_back('L');
    m[6].push_back('M');m[6].push_back('N');m[6].push_back('O');
    m[7].push_back('P');m[7].push_back('Q');m[7].push_back('R');m[7].push_back('S');
    m[8].push_back('T');m[8].push_back('U');m[8].push_back('V');
    m[9].push_back('W');m[9].push_back('X');m[9].push_back('Y');m[9].push_back('Z');
    }
    void printAlphabet(char *x, int t)
    {
    int len=strlen(x);
    int x1;
    if(len==t)
    {
    printf("%s\n",x);
    return;
    }
    x1=x[t]-'0';
    for(int i=0;i<m[x1].size();i++)
    {
    x[t]= m[x1][i];
    printAlphabet(x,t+1);
    x[t]=x1+'0';
    }
    }
    int main()
    {
    char x[100];
    generate();
    scanf("%s",x);
    printAlphabet(x,0);
    return 0;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager

If you are trying to get started with Janus Graph with Apache Cassandra. You may get the following error. Caused by: org.janusgraph.diskstorage.TemporaryBackendException: Temporary failure in storage backend at org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager.getCassandraPartitioner(CassandraThriftStoreManager.java:219) ~[janusgraph-cassandra-0.2.0.jar:na] at org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager.<init>(CassandraThriftStoreManager.java:198) ~[janusgraph-cassandra-0.2.0.jar:na] ... 48 common frames omitted Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused (Connection refused) at org.apache.thrift.transport.TSocket.open(TSocket.java:187) ~[libthrift-0.9.2.jar:0.9.2] at org.apache.thrift.transport.TFramedTransport.open(TFramedTransport.java:81) ~[libthrift-0.9.2.jar:0.9.2] at org.janusgraph.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory.makeR...

com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server

If you are trying to connect Mongo DB Server and it insanely throwing following error. com.mongodb.MongoTimeoutException : Timed out after 1000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=192.168.1.10:27010, type=UNKNOWN, state=CONNECTING, exception={ com.mongodb.MongoSecurityException: Exception authenticating MongoCredential {mechanism=null, userName='user123', source='admin', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18 : 'Authentication failed.' on server 192.168.1.10:27010 . The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}}] If you start looking the error content First you encounter with Timeout Exception which may mislead you. It is basically an authentication error. I...

Move like a Ninja on Terminal Console

If you are in IT and do a lot of stuff on terminal, this is the post for you. In the following post, we will explore various key shortcuts to jump and edit on console. Note:- Short keys may behave differnt on differnt OS systems. These keys best work with Linux sytem, For mac OS you have to enable Option key as Meta key in case of Alt . I have never checked these on windows, Please share your experinece with windows in comments. ------------------------------------------------------------------ Edit Control Move forward one char: Ctrl + f Move backward one char: Ctrl + b Move forward one word: Alt + f Move backward one word: Alt + b Move to end: Ctrl + e #Like End Move to start: Ctrl + a #Like Home Jump toggle between current location and start: Ctrl + xx Delete forward one char: Ctrl + d #Like Delete Delete backward one char: Ctrl + h #Like Backspace Delete forward one word: Alt + d Delete backward one word: Ctrl + w Delete to end: Ctrl + k Delete to start: Ctrl + u Undo: Ct...