Advertisement
satishfrontenddev5

Untitled

Feb 22nd, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.
  2.  
  3. Formally the function should:
  4.  
  5. Return true if there exists i, j, k
  6.  
  7. such that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.
  8.  
  9. Note: Your algorithm should run in O(n) time complexity and O(1) space complexity.
  10.  
  11. Input format
  12. First Line Contains an Integer T: no of test cases.
  13.  
  14. For each test case the first line contains an integer N: No of elements in the array.
  15.  
  16. Second line contains N space separated integers.
  17.  
  18. Output format
  19. output either true or false
  20.  
  21. Sample Input 1
  22. 5
  23.  
  24. 1 2 3 4 5
  25.  
  26. Sample Output 1
  27. true
  28.  
  29. Explanation 1
  30. Here A[0] < A[1] <A[2] hence true
  31.  
  32. Constraints
  33. 1 <= T <= 1000
  34.  
  35. 1 <= N <= 10^5
  36.  
  37. 0 <= A[i] <= |10^9|
  38.  
  39. It is guaranteed that sum of N over all test cases is less than 5*10^5.
  40.  
  41.  
  42. #include <bits/stdc++.h>
  43. using namespace std;
  44.  
  45. string increasingTripleSubsequence(int n, vector<int> & nums) {
  46.  
  47. }
  48.  
  49.  
  50. int main() {
  51.     int t, n;
  52.     cin >> t;
  53.     while (t--) {
  54.         cin >> n;
  55.         vector<int> nums(n);
  56.         for (int i = 0; i < n; i++) {
  57.             cin >> nums[i];
  58.         }
  59.         string ans = increasingTripleSubsequence( n, nums);
  60.         cout << ans << endl;
  61.     }
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement