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.
- #include<iostream>
- #include<cstdio>
- #include<bitset>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<map>
- #include<set>
- #include<list>
- #include<stack>
- #include<string>
- #include<cstdlib>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- #define fori(i,n) for(i=0;i<(n);++i)
- #define forin(i,s,n) for(i=(s);i<=(n);++i)
- #define forn(i,n) for(i=(n-1);i>=0;--i)
- #define forni(i,n,e) for(i=(n);i>=(e);--i)
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
- #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
- #define SQ(X) ( (X) * (X) )
- #define nil NULL
- #define itr iterator
- #define pb push_back
- #define mod 1000000007 //10^9+7
- #define P printf
- #define S scanf
- //#define getchar getchar_unlocked //Uncomment this if you are going to use fast i/o
- typedef long long int lli;
- typedef long double ld;
- typedef vector<int> vi;
- typedef vector<lli> vll;
- typedef pair<int,int> ii;
- /*------------------------------------------------------------------------------
- ++++++++++++++++++++++++++++++++Source Code+++++++++++++++++++++++++++++++++++++
- ------------------------------------------------------------------------------*/
- //Functions and Global variables
- void program();
- inline void pAry(int a[],int n)
- {
- int i;
- fori(i,n)
- printf("%d ",a[i]);
- printf("\n");
- }
- inline void pSAry(int a[],int s,int e)
- {
- int i;
- forin(i,s,e)
- printf("%d ",a[i]);
- printf("\n");
- }
- //int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
- //double pi=2*acos(0.0);
- stack<int> va_stk;
- queue<int> dg_q;
- stack<char> op_stk;
- map<char,int> p_map;
- int eval(char op)
- {
- if((int)va_stk.size() < 2)
- { P("Given expression is not valid\n");
- return 0;
- }
- int o1,o2;
- o2= va_stk.top();
- va_stk.pop();
- o1=va_stk.top();
- va_stk.pop();
- switch(op)
- {
- case '+':
- return o1+o2;
- case '-':
- return o1-o2;
- case '*':
- return o1*o2;
- case '/':
- return o1/o2; //You can add more operator here if you need
- default:
- P("Undefined Operator\n");
- return 0;
- }
- }
- //Main()
- int main()
- {
- //freopen("IN.txt", "r", stdin);
- //freopen("OUT.txt", "w", stdout);
- p_map['(']=0;
- p_map['+']=1;
- p_map['-']=1;
- p_map['*']=2;
- p_map['/']=2;
- program();
- return 0;
- }
- //Root Program
- void program()
- {
- char s[100];
- S("%s",s);
- int i=0;
- while(s[i]!=0)
- {
- if(s[i]>='0' && s[i]<='9')
- {
- dg_q.push(s[i]-'0');
- }
- else
- {
- //You have to take care extra if parenthesis and exponent operator
- // present in expression
- int var=0;
- while(!dg_q.empty())
- {
- var=10*var + dg_q.front();
- dg_q.pop();
- }
- va_stk.push(var);
- if(op_stk.empty())
- {
- op_stk.push(s[i]);
- }
- else
- {
- while((!op_stk.empty()) && (p_map[op_stk.top()] >= p_map[s[i]]))
- {
- int temp=eval(op_stk.top());
- va_stk.push(temp);
- op_stk.pop();
- }
- op_stk.push(s[i]);
- }
- }
- i++;
- }
- int var=0;
- while(!dg_q.empty())
- {
- var=10*var + dg_q.front();
- dg_q.pop();
- }
- va_stk.push(var);
- while(!op_stk.empty())
- {
- int temp=eval(op_stk.top());
- va_stk.push(temp);
- op_stk.pop();
- }
- int value=va_stk.top();
- va_stk.pop();
- if(va_stk.empty())
- {
- P("The value of expression is %d\n",value);
- }else
- {
- P("The give expression is not valid\n");
- }
- }
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.
- #include<iostream>
- #include<cstdio>
- #include<bitset>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<map>
- #include<set>
- #include<list>
- #include<stack>
- #include<limits>
- #include<string>
- #include<cstdlib>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- #define fori(i,s,n) for(i=(s);i<=(n);++i)
- #define forn(i,n,e) for(i=(n);i>=(e);--i)
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
- #define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
- #define SQ(X) ( (X) * (X) )
- #define nil NULL
- #define itr iterator
- #define pb push_back
- #define mod 1000000007 //10^9+7
- #define P printf
- #define S scanf
- //#define getchar getchar_unlocked //Uncomment this if you are going to use fast i/o
- typedef long long int lli;
- typedef long double ld;
- typedef vector<int> vi;
- typedef vector<lli> vll;
- typedef pair<int,int> ii;
- /*------------------------------------------------------------------------------
- ++++++++++++++++++++++++++++++++Source Code+++++++++++++++++++++++++++++++++++++
- ------------------------------------------------------------------------------*/
- //Functions and Global variables
- void program();
- inline void pAry(int a[],int s,int e)
- {
- int i;
- fori(i,s,e)
- printf("%d ",a[i]);
- printf("\n");
- }
- //int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
- //double pi=2*acos(0.0);
- //Main()
- int main()
- {
- //freopen("IN.txt", "r", stdin);
- //freopen("OUT.txt", "w", stdout);
- program();
- return 0;
- }
- //Root Program
- void program()
- {
- int n;
- S("%d",&n);
- int num[10];
- int i,num_size;
- //store the number into an array integer
- stack<int> stk;
- if(n==0)
- {
- num[0]=0;
- num_size=1;
- }
- else
- {
- while(n>0)
- {
- stk.push(n%10);
- n/=10;
- }
- i=0;
- while(!stk.empty())
- {
- num[i++]=stk.top();
- stk.pop();
- }
- num_size=i;
- }
- //pAry(num,0,num_size-1);
- int total,grand_total,block,j,k;
- const char hashTable[10][5] = {"", "", "abc", "def", "ghi", "jkl",
- "mno", "pqrs", "tuv", "wxyz"};
- total=1;
- fori(i,0,num_size-1)
- {
- total*=(strlen(hashTable[num[i]]));
- }
- cout<<"Total "<<total<<endl;
- grand_total=total;
- char table[grand_total+5][num_size+2];
- fori(i,0,num_size-1)
- {
- int idx=0;
- int ws=strlen(hashTable[num[i]]);
- block=total/ws;
- fori(j,0,ws-1)
- {
- fori(k,0,block-1)
- {
- table[idx++][i]=hashTable[num[i]][j];
- }
- }
- while(idx<grand_total)
- {
- table[idx][i]=table[idx%total][i];
- idx++;
- }
- total=block;
- }
- fori(i,0,grand_total-1)
- {
- table[i][num_size]='\0';
- cout<<table[i]<<endl;
- }
- }
Note:- For any suggestion and query regarding this post please comment below.
Comment By: victorious28 June 2015 at 05:58
ReplyDeleteusing namespace std;
ReplyDeletemap > 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;
}