# Solution in O(1) only 4 Lines Code

• Hello Guys!

I know after watching code definitely you will say you nailed it. That's why this problem is in Easy.

In problem it's clearly says that there are only 8 possibility of the input, so i find answer for every input and store it into the array and return answer directly by using input as index.

For example if n=2 and answer = 987, so i store 987 in array at 2nd position.

So whole array will be look like `{0,9,987,123,597,677,1218,877,475}`.

Here's the code.

``````int[] ans = {0,9,987,123,597,677,1218,877,475};
if(n>=1 && n<=8)
return ans[n];
return 0;
``````

• @dharmikjogi You aren't serious..are you? lol

• @labs Yes i am serious. I know nobody will believe because LeetCode has such great test cases for every problem set. I submitted this code and it works. You can check also.

• @dharmikjogi Lol..I didn't mean that. I know the code will work if you have valid answers. I was wondering if you were implying or not if it was just a hack.

• Something is wrong with the runtime system here. This constant look-up solution only beats 45.36% of submissions. What can possibly be faster than this??!!

• @lijenpan I think you will get different runtimes every time you submit your solution. And the range could be very large. And I agree, this should be the fastest solution. LOL...

• @lijenpan In what language did you submit it, and what was the time in ms? And what makes you think there's something faster?

• For example if n=2 and answer = 987, so i store 987 in array at 2nd position.

In interview we don't have luxury of giving output for every test input in a list or array

• @sha256pki
Yes you are right that in interview we don't have all type of test cases and expected output.

But in interview, at least we will check for different inputs and when you are told explicitly that you will have input between range A and B which is so small then you should check for all.

And i know that interviewer will not impress with this solution but you should tell him that,
`"I know that, this solution is not what you expected, but this skills will work when when we are with the client or giving demo to the client, and some unexpected error occurred then, at that time we don't have sufficient time to solve that error and can't tell to client that some error occurred, so at that time it's better to fix that error anyhow and handle client and then after that we can fix properly so that this type of error will never occurs again."`

This will make an impression on interviewer.

I hope you will understand my point.

• ``````int largestPalindrome(int n) {
return ((int []){0,9,987,123,597,677,1218,877,475})[n];
}
``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.