How do you detect cheating?
aamirmahmood
@aamirmahmood
Posts made by aamirmahmood

RE: [IMPORTANT NOTICE] Cheating Announcement

Simple C# Code
private static bool IsPalin(char[] value, int pos, int len) { for (int i = pos, j = pos + len  1; i < j; i++, j) { if (value[i] != value[j]) return false; } return true; } public string LongestPalindrome(string s) { var arr = s.ToCharArray(); for (int len = arr.Length; len > 0; len) { for (int pos = 0; pos + len <= s.Length; pos++) { if (IsPalin(arr, pos, len)) return s.Substring(pos, len); } } return s; }

RE: Two Sum
People thinking that hashtables or hashmaps work like magic is nonsense. It is unpredictable and varies based on the hash function. A very good hash function will have a same number of hashes as the number of input values. So in this case if your input array is filled with numbers from all over the range, you might be allocating a big amount of memory based on how your hashtable is implemented.
I try not to use hash table as much as possible, the give and illusion of constant time, but what is the benefit if that constant time is a long time. And at the same time memory consumption is not guaranteed.
I would stick with the more predictable O(n x n) solution as it is predictable and runs in a constant memory.