0% found this document useful (0 votes)
21 views3 pages

Wipro

Wipro talentnext logic building question

Uploaded by

Suman Bhatnagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Wipro

Wipro talentnext logic building question

Uploaded by

Suman Bhatnagar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
Find the longest increasing subsequence of a given array of integers, A. In other words, find a subsequence of an array in which the subsequence’s elements are in strictly increasing order and in which the subsequence is as long as possible. In this case, we only care about the length of the longest increasing subsequence. Input Format: The first and only argument is an integer array A. Output Format: Return an integer representing the length of the longest increasing subsequence. ‘Sample Input: 1275 Output: ‘The sequence : [1, 2, 7] ‘Sample Input: 0841221061419513311715 Output: The sequence : [0, 2, 6, 9, 13, 15] or [0, 4, 6, 9, 11, 15] or [0, 4, 6, 9, 13, 15) public int[] lis(int[) arr) { Sa Me Da ae Co) 4 int[] dp = new int[n]; for (int i = 0; i < nj i++) { dp[i] = 1; for (int j = 0; j < i; j++) { if (arr[i] > arr[j] && dp[i] < dp[j] dp[i] = dp[j] + 1; Mi int max_len = max(dp) ; int[] res = new int[max_len]; cae ee ee while (i >= @ && max_len > Cee if (dp[i] == max_len) { res[max_len - 1] = arr[i]; Li) ae CT H ae an return res[:: =1)]; 3 .-.Program finished with exit code 0 Press ENTER to exit console. ites

You might also like