Amazon Interview Question
Software Engineer / Developers<pre lang="java" line="1" title="CodeMonkey82409" class="run-this">#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<cassert>
#include<climits>
using namespace std;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef pair<int,int> ii;
typedef pair<int,ii> pii;
typedef long long LL;
#define sz(c) (int)c.size()
#define pb push_back
#define all(v) v.begin(),v.end()
#define inc(i,n) for(int i=0;i<n;i++)
#define dec(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000
#define F first
#define S second
#define PRV(V) inc(i,sz(V)) cout<<V[i]<<" ";cout<<endl
main(){
string s;
cin>>s;
int maxLen =0;
for(int i=0;i<s.size();i++){
int len = 1;
for(int j=i-1,k=i+1;j>=0 && k<s.size();j--,k++)
if(s[j]==s[k])
len+=2;
else
break;
maxLen = max(maxLen,len);
len = 0;
for(int j=i,k=i+1;j>=0 && k<s.size();j--,k++){
if(s[j]!=s[k])
break;
else
len+=2;
}
maxLen = max(maxLen,len);
}
cout<<maxLen<<endl;
return EXIT_SUCCESS;
}
</pre><pre title="CodeMonkey82409" input="yes">
</pre>
Odd or Even length string
- ankushbindlish May 23, 2010null string
normal string
naming convention
xml summary comments
Proper Indentation
Dry Run of the program
Case sensitive or insensitive comparison
All Return paths need to be validated.