Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 662 |

@arpitsatnalika | 629 |

@code_it_ | 591 |

@prakharxyz | 583 |

@tujhekya | 542 |

@Rahul Jadhav 1 | 458 |

@sivanandh03 | 448 |

@satyam0460 | 433 |

@iamronak | 424 |

@imnm | 424 |

@18eumc107 | 421 |

Complete Leaderboard |

Find the first non-repeating element in a given array** A** of **N** integers.

**Note:** Array consists of only positive and negative integers and **not zero**.

**Input:**

The first line of input is an integer** T**, denoting the number of test cases. Each test case has subsequent two lines of input. First line is an integer **N**, denoting size of integer array **A**. Second line consists of **N** space separated integers of the array **A**.

**Output:**

For each testcase, print the required answer. If no such element exists, then print **0**

**Constraints:**

1 <= T <= 100;

1 <= N <= 10^{7};

-10^{16} <= A_{i }<= 10^{16}

{A_{i} !=0 }

**Example:
Input:**

4

5

-1 2 -1 3 2

6

9 4 9 6 7 4

3

1 1 1

2

-3 2

3

6

0

-3

**Explanation:**

**Testcase1: **-1 and 2 are repeating whereas 3 is the only number occuring once. Hence, the output is 3.

**Testcase2:** There are 3 distinct integers, 9, 4 and 5, but they all are repeating. There is no non-repetitive element in the array. Hence, the output is **0**.

**Testcase3:** -1 and 3 are non-repeating. -1 occurs before 3 in the array. Hence, the output is -1.

**Testcase4:** There are two distinct elements occuring only once in the array, with 6 occuring before 7. Hence, output is 6.

**Testcase5:** The only non-repeating element is -3. Hence, output is -3.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Non-Repeating Element

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.