Fastest unique finder Given 4096 16-bit integers, only four of which are unique and others appeared twice (so 2050 different integers exist). Find the four uniques.
To time precisely and limit RAM usage, your program will be run on a 12MHz 8051(with 128B RAM). I'll test with a random case generated by some code to test, but we aim at the worst case, so anyone can provide other test cases.
You can answer in C or ASM, but C will likely give some extra disadvantage. The input array is placed on ROM 0xE000-0xFFFF, and output is placed on extra write-only RAM 0x00-0x07. When you finish outputting, clear P3.5.
A C code that solves the problem with bad score, to better understand the I/O way:
#include &lt;reg51.h&gt;
sbit P3_5 = P3^5;
unsigned int code input[4096] _at_ 0xE000;
unsigned int pdata output[4] _at_ 0x00;
void main() {
    unsigned long i;
    unsigned int j;
    unsigned char cnt, wr = 0;
    for (i=0; i&lt;65536L; ++i) {
        cnt = 0;
        for (j=0; j&lt;4096; ++j) {
            if (input[j] == i) ++cnt;
        }
        if (cnt==1) { // Order doesn't matter
            output[wr++] = i;     
        }
    }
    P3_5 = 0;
    while (1);
}

According to test this runs for 04:19:36.997507. Also see the example ASM solution that solve in several seconds.

For extreme push, I'll run the simulation on Proteus with such circuit:

and check the time when DBT1 is actived.

You can use all ROM in 0000-DFFF.
You can assume RAM is initialized to 0.
You can use SFRs, including pins, as RAM
You don't need to jmp $ after clearing P3.5
You can write trash into outer RAM 08-FF, they'll be ignored
C, 0.480298s
Codes

#ifndef LOCAL_DEBUG
#include &lt;reg51.h&gt;
sbit P3_5 = P3 ^ 5;
unsigned int code input[4096] _at_ 0xE000;
unsigned int pdata output[4] _at_ 0x00;
#else

#include &lt;stdio.h&gt;
#define int short

#define UNIQ1 17
#define UNIQ2 273
#define UNIQ3 1298
#define UNIQ4 1554

unsigned int input[4096] = {
UNIQ1,
UNIQ2,
UNIQ3,
UNIQ4
};
unsigned int output[4];

#endif

#define INPUT_SIZE 4096
#define BUCKET_BITS 4
#define BUCKET_SIZE (1 &lt;&lt; (BUCKET_BITS))
#define BUCKET_MASK ((BUCKET_SIZE) - 1)

unsigned int buckets[BUCKET_SIZE];

#define buckets_value(n) (buckets[n] &amp; ~(bucket_mask)) | ((n) &lt;&lt; bit_offset)

void main() {
  unsigned int output_offset = 0;
  unsigned int i, j, k, l;
  unsigned int search_bucket = 0, search_bucket_2 = 0, bit_offset = 0, bit_offset_2, bucket_mask;
  unsigned int target_mask, target_value;
  do {
    bucket_mask = BUCKET_MASK &lt;&lt; bit_offset;
    for (i = 0; i &lt; BUCKET_SIZE; ++i) {
      buckets[i] = 0;
    }
    for (i = 0; i &lt; INPUT_SIZE; ++i) {
      buckets[(input[i] &gt;&gt; bit_offset) &amp; BUCKET_MASK] ^= input[i] | bucket_mask;
    }
    for (i = j = 0; i &lt; BUCKET_SIZE; ++i) {
      if (buckets[i] != 0) ++j;
    }
    if (j &lt;= 1) {
      bit_offset += BUCKET_BITS;
    }
  } while (j &lt;= 1);
  if (j == 4) {
    for (i = 0; i &lt; BUCKET_SIZE; ++i) {
      if (buckets[i] == 0) continue;
      output[output_offset++] = buckets_value(i);
    }
  } else if (j == 3) {
    for (i = 0; i &lt; BUCKET_SIZE; ++i) {
      if (buckets[i] == 0) continue;
      if (buckets[i] &amp; (BUCKET_MASK &lt;&lt; bit_offset)) {
        output[output_offset++] = buckets_value(i);
      } else {
        search_bucket = i &lt;&lt; bit_offset;
      }
    }
  } else if (j == 2) {
    for (i = k = 0; i &lt; BUCKET_SIZE; ++i) {
      if (buckets[i] == 0) continue;
      if (buckets[i] &amp; (BUCKET_MASK &lt;&lt; bit_offset)) {
        l = buckets_value(i);
        if (k == 0) {
          for (j = 0; j &lt; INPUT_SIZE; ++j) {
            if (input[j] == l) ++k;
          }
          if (k == 1) {
            output[output_offset++] = l;
          } else {
            search_bucket = i &lt;&lt; bit_offset;
            k = 2;
          }
        } else if (k == 1) {
          search_bucket = i;
        } else {
          output[output_offset++] = l;
        }
      } else {
        if (search_bucket) {
          search_bucket_2 = i &lt;&lt; bit_offset;
        } else {
          search_bucket = i &lt;&lt; bit_offset;
        }
      }
    }
  }
  bit_offset_2 = bit_offset;
  target_mask = BUCKET_MASK &lt;&lt; bit_offset;
  target_value = search_bucket;
  while (output_offset &lt; 4) {
    bit_offset += BUCKET_BITS;
    bucket_mask = BUCKET_MASK &lt;&lt; bit_offset;
    for (i = 0; i &lt; BUCKET_SIZE; ++i) {
      buckets[i] = 0;
    }
    for (i = 0; i &lt; INPUT_SIZE; ++i) {
      if ((input[i] &amp; target_mask) != target_value) continue;
      buckets[(input[i] &gt;&gt; bit_offset) &amp; BUCKET_MASK] ^= input[i] | bucket_mask;
    }
    for (i = j = 0; i &lt; BUCKET_SIZE; ++i) {
      if (buckets[i] != 0) ++j;
    }
    if (j == 1) {
      continue;
    }
    for (i = 0; i &lt; BUCKET_SIZE; ++i) {
      if (buckets[i] == 0) continue;
      if ((buckets[i] &gt;&gt; bit_offset) &amp; BUCKET_MASK) {
        output[output_offset++] = buckets_value(i);
        --j;
      } else {
        target_mask |= bucket_mask;
        target_value |= i &lt;&lt; bit_offset;
      }
    }
    if (j == 0) {
      bit_offset = bit_offset_2;
      target_mask = BUCKET_MASK &lt;&lt; bit_offset;
      target_value = search_bucket_2;
    }
  }
#ifndef LOCAL_DEBUG
  P3_5 = 0;
  while (1);
#else
  for (i = 0; i &lt; 4; i++) {
    printf(&quot;%d\n&quot;, output[i]);
  }
#endif
}

Try it online!
I'm not sure about its correctness. Please comment if you find out some failed testcases. I will try my best to fix it.

Algorithm
Algorithm here only works when input array contains 4 unique values. It will fail if input array contains more than 4 values.
Consider xor of some numbers where most numbers occurred 2 times, and some occurred once. It is easy to prove: The xor result is zero if and only if we have at least 3 unique numbers here. Also, we try to count how many numbers at all. It is trivial to know: If the count is even / odd, then we have even / odd number of unique numbers here.
As there are only 4 unique numbers according to the description of this question. If both xor result is zero and count result is even, there should be 0 or 4 unique numbers.
By using this idea, we need to split numbers into some buckets while keep equals number in same buckets. You can do it by (input[i] &gt;&gt; n) &amp; m. So we first split all values input[i] into 16 buckets based on (input[i] &gt;&gt; 0) &amp; 15. We use input[i] | bucket_mask to mask out the bits for bucket name. We set them to 1s, so they are used to know count number in that buckets is odd or even.
for (i = 0; i &lt; INPUT_SIZE; ++i) {
  buckets[(input[i] &gt;&gt; bit_offset) &amp; BUCKET_MASK] ^= input[i] | bucket_mask;
}

We use above code. And after calculate these buckets:

If buckets[i] &amp; bucket_mask is non-zero: we know the bucket i contains 1 or 3 unique numbers (number count is odd).
If buckets[i] &amp; bucket_mask is zero, but buckets[i] is non-zero: we know the bucket i contains 2 unique numbers.
If buckets[i] is zero, and some other bucket bucket[j] is non-zero: we know the bucket i contains no unique numbers.
If all buckets are zero: 4 unique numbers are located in the same bucket. We need to try another 4 bits as mask and run the loop again.

After we know where the number is in some bucket:

If the bucket contains only 1 unique numbers: the unique number is (buckets[i] &amp; ~(bucket_mask)) | ((i) &lt;&lt; bit_offset);
If the bucket contains more than 1 unique numbers: We loop again on numbers in this bucket, and split them into different buckets based on other bits;


Analysis
Time complexity is \$O\left(size \cdot bit  / buckets + 2^{buckets} \right)\$. \$size\$ is how many numbers the input contains. \$bit\$ is how many bits each input contains. \$bucket\$ is how many bits for bucket id (4 in above codes).
Extra storage complexity is \$O\left(2^{buckets}\right)\$.