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 |

Given an array **A** of **N** integers, find any 3 elements in it such that A[i] < A[j] < A[k] and i < j < k.

**Example 1:**

Input:N = 5 A[] = {1,2,1,1,3}Output:1Explanation:a sub-sequence 1 2 3 exist.

**Example 2:**

Input:N = 3 A[] = {1,1,3}Output:0Explanation:no such sub-sequence exist.

**Your Task:**

Your task is to complete the function **find3Numbers** which finds any 3 elements in it such that A[i] < A[j] < A[k] and i < j < k. You need to return them as a vector/ArrayList/array (depending on the language cpp/Java/Python), if no such element is present then return the empty vector of size 0.

**Note**: The output will be 1 if the sub-sequence returned by the function is present in array A else 0. If the sub-sequence returned by the function is not in the format as mentioned then the output will be -1.

**Expected Time Complexity: **O(N)

**Expected Auxiliary Space: **O(N)

**Constraints:**

1 <= N <= 10^{5}

1 <= A[i] <= 10^{6}, for each valid i

**Note: **The **Input/Output** format and **Examples** given are used for the system's internal purpose, and should be used by a user for **Expected Output** only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

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
Sorted subsequence of size 3

...

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