Error
|
|
---|---|
@Ibrahim Nash | 6379 |
@blackshadows | 6329 |
@mb1973 | 5358 |
@Quandray | 5231 |
@akhayrutdinov | 5111 |
@saiujwal13083 | 4510 |
@sanjay05 | 3762 |
@marius_valentin_dragoi | 3522 |
@sushant_a | 3459 |
@verma_ji | 3357 |
@KshamaGupta | 3318 |
Complete Leaderboard | |
|
|
@ritiksethi21 | 1050 |
@aroranayan999 | 807 |
@RizulBansal | 685 |
@ashishtrehan002 | 538 |
@hemantgarg923 | 528 |
@simrangoyal | 526 |
@ronaldo77 | 520 |
@anishrajan | 505 |
@thanosagain | 505 |
@ssparteek470 | 495 |
@rahul2312 | 491 |
Complete Leaderboard |
Find the first non-repeating element in a given array arr of N integers.
Note: Array consists of only positive and negative integers and not zero.
Example 1:
Input : arr[] = {-1, 2, -1, 3, 2}
Output : 3
Explanation:
-1 and 2 are repeating whereas 3 is
the only number occuring once.
Hence, the output is 3.
Example 2:
Input : arr[] = {1, 1, 1}
Output : 0
Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function firstNonRepeating() that takes an array (arr), sizeOfArray (n), and returns the first non-repeating element. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).
Constraints:
1 <= N <= 107
-1016 <= Ai <= 1016
{Ai !=0 }
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes