Skip to content

Commit

Permalink
Add Longest_Increasing_Subsequence in Kotlin (jainaman224#2935)
Browse files Browse the repository at this point in the history
Updated LIS
  • Loading branch information
sandhyabhan authored May 31, 2020
1 parent 9f500f9 commit 5de74e2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Longest_Increasing_Subsequence/Longest_Increasing_Subsequence.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//Kotlin code for Longest increasing subsequence

class LIS
{
fun lis(int:arr[], int:n):int
{
int lis[] = new int[n];
int result = Integer.MIN_VALUE;

for (i in 0 until n)
{
lis[i] = 1;
}

for (i in 1 until n)
{
for (j in 0 until i)
{
if (arr[i] > arr[j] && lis[i] < lis[j] + 1)
{
lis[i] = lis[j] + 1;
}
}
result = Math.max(result, lis[i]);
}
return result;
}

fun main()
{
var read = Scanner(System.`in`)
println("Enter the size of the Array:")
val arrSize = read.nextLine().toInt()
var arr = IntArray(arrSize)
println("Enter elements")

for(i in 0 until arrSize)
{
arr[i] = read.nextLine().toInt()
}

int n = arrSize;
println("\nLength of the Longest Increasing Subsequence:" + lis(arr, n))
}
}

/*
Enter the size of the array : 8
Enter elements : 15 26 13 38 26 52 43 62
Length of the Longest Increasing Subsequence : 5
*/

0 comments on commit 5de74e2

Please sign in to comment.