Getting one over the system (O(1) solution in Java)
So I spend 30 mins (and 5 bugs) trying to get my O(N^2) solution to work. It doesn\'t. So I get mad and rage-generate an array of all the palindromic primes usi
So I spend 30 mins (and 5 bugs) trying to get my O(N^2) solution to work. It doesn\'t. So I get mad and rage-generate an array of all the palindromic primes using 1553 ms. Next, I put them into my revenge array.\n\n```\nclass Solution {\n    private final int[] hehehe = new int[]{2, 3, 5, 7, 11, 101, 131, 151, 181, 191, \n\t\t313, 353, 373, 383, 727, 757, 787, 797, 919, 929, 10301, 10501, 10601, \n\t\t11311, 11411, 12421, 12721, 12821, 13331, 13831, 13931, 14341, 14741, \n\t\t15451, 15551, 16061, 16361, 16561, 16661, 17471, 17971, 18181, 18481, \n\t\t19391, 19891, 19991, 30103, 30203, 30403, 30703, 30803, 31013, 31513, \n\t\t32323, 32423, 33533, 34543, 34843, 35053, 35153, 35353, 35753, 36263, \n\t\t36563, 37273, 37573, 38083, 38183, 38783, 39293, 70207, 70507, 70607, \n\t\t71317, 71917, 72227, 72727, 73037, 73237, 73637, 74047, 74747, 75557, \n\t\t76367, 76667, 77377, 77477, 77977, 78487, 78787, 78887, 79397, 79697, \n\t\t79997, 90709, 91019, 93139, 93239, 93739, 94049, 94349, 94649, 94849, \n\t\t94949, 95959, 96269, 96469, 96769, 97379, 97579, 97879, 98389, 98689, \n\t\t1003001, 1008001, 1022201, 1028201, 1035301, 1043401, 1055501, \n\t\t1062601, 1065601, 1074701, 1082801, 1085801, 1092901, 1093901, \n\t\t1114111, 1117111, 1120211, 1123211, 1126211, 1129211, 1134311...};\n```\nYou get the idea.\nO(1) solution I got after brute-forcing all the primes I needed.\n```\n    public final int[] hehehe; //(see above)\n    public int primePalindrome(int N) {\n        //2lazE to implement binary search\n        for(int i = 0; i < hehehe.length; i++){\n            if(N <= hehehe[i]){\n                return hehehe[i];\n            }\n        }\n        return -1;\n    }\n}\n```\n\nIt didn\'t nab me for memory usage LOL. Check out the C++ one also, its faster (coder used binary search) and was posted first.
[]