Question 2 – Special LIS

Special LIS

Here, in this page we will discuss one of the problem Special LIS that was asked in InfyTQ Advance Coding Section. We will discuss the problem description along with function description, Test Cases along with there explanation.

You will find the solution of the problem in different programming language. 

Special LIS Problem statement-:

 

Given an array of N integers. Find the length of the longest increasing subsequence such that the difference between adjacent elements of the longest increasing subsequence is also increasing.

Note: It’s not required that the sequence should have strictly increasing numbers and the differences are also not required to be strictly increasing.

Ex: [1,2,3,4,5]. The longest increasing subsequence will be [1,2,4,5] but the difference array in this case is [1,2,1] which is not increasing. If we consider [1,2,4] or [1,2,5] then the numbers as well as the differences are in increasing order.

 

Function Description:

Complete the specialLIS function in the editor below. It has the following parameter(s):

Parameters:

NameTypeType
sizeIntegersize of array
arrInteger arrayarray

Return:

The function must return an INTEGER denoting the length of the longest increasing sub sequence with increasing differences.

 

Constraints:

  • 1 <= size <= 500
  • 1 <= arr[i] <= 10^5

 

Input Format:

  • The first line contains integer, size, denoting the size of the array.
  • Each line i of the size subsequent lines (where 0 <= i < size) contains an integer describing the ith elements of the array.

 

Sample Cases

  • Sample Input 1
    5
    1
    2
    3
    4
    5

 

  • Sample Output 1
    5