0% found this document useful (0 votes)
35 views1 page

Logic Builiding Exercise 1

The document describes finding the longest increasing subsequence (LIS) in an integer array. It provides the function prototype that takes an integer array as input and returns the length of the LIS. It gives 4 examples of finding the LIS of sample arrays and explains the outputs.

Uploaded by

SHIVA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views1 page

Logic Builiding Exercise 1

The document describes finding the longest increasing subsequence (LIS) in an integer array. It provides the function prototype that takes an integer array as input and returns the length of the LIS. It gives 4 examples of finding the LIS of sample arrays and explains the outputs.

Uploaded by

SHIVA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Day 1: Longest Increasing sequence (LIS)

Given an integer array, find the length of its longest increasing sequence.

The prototype of the function is as below:


public static void longestIncreasingSeq(int input1, int[] input2);
The function takes as input an integer input1 and an integer array input2,
containing input1 number of integers, and sets the output1 variable to the length of its LIS
(longest increasing sequence).
Example 1:
input1 = 9
input2[] = {11,3,4,7,8,12,2,3,7}
output1 should be 5.
Explanation:
In the given array input2, the two increasing sequences are “3,4,7,8,12” and “2,3,7”. The first
sequence i.e. “3,4,7,8,12” is the longer one containing five items. So, the longest increasing
sequence = 5.

Example 2:
input1 = 4
input2[] = {1,3,2,1}
output1 should be 2

Explanation:
In the given array input2, the increasing sequence is “1,3” containing two items. So, the
longest increasing sequence = 2.

Example 3:
input1 = 12
input2[] = {12,17,21,3,7,9,10,11,33,100,4,8}
output1 should be 7

Explanation:
In the given array input2, the increasing sequences are “12,17,21” containing three items,
“3,7,9,10,11,33,100” containing seven items and “4,8” containing two items. So, the longest
increasing sequence = 7
.Example 4:
input1 = 6
input2[] = {12,11,10,9,8,7}
output1 should be 0
Explanation:
In the given array input2, there is NO increasing sequence. All the items are in decreasing
order, hence the longest increasing sequence = 0

You might also like