ashishB
BAN USER
Comments (6)
Reputation 70
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
Simplest solution would be to maintain a counter for every number as you proceed through an array. For eg= Array A = [1,2,3,3,3,4,5] , Counter[1] = 1, counter[2] = 1 counter [3] =1, then when a pointer comes to 3 again, it will not add that element into a result array as counter[3] is already one. This will take O(n) time. The solution is best suited when space constraints are not given.
- ashishB September 23, 2013Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
7
of 7 vote
Simple trick would be to reverse a number and check if it is equal to original number.
If yes, number is a palindrome.
main()
{
int temp1, temp2;
int n=0;
printf("Number plz");
scanf("%d",&temp1);
temp2=temp1;
while(temp2!=0)
{
n=n*10;
n=n+temp2%10;
temp2=temp2/10;
}
if(temp1==n)
printf("palindrom found");
else
printf("no palindrome");
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Correct me if i am wrong, but does this essentially mean that we are searching a row from a 2D array where every element except a[i][j] (where i=j) are O.
- ashishB September 24, 2013