Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Mark is a young Jedi, but he cannot yet fully control the Force. He exercises by

ID: 3804377 • Letter: M

Question

Mark is a young Jedi, but he cannot yet fully control the Force. He exercises by floating through the air, fighting gravity, and taking height measurements (in millimeters) every second. After he falls to the ground, he up, ignores pain, tries to estimate the of time (in seconds) through which he was continuously rising. He is not very good Respectively, because Jedi apprentices train to be heroic, not intelligent. he needs your help. Input Standard input (system.in) contains one line of integers, separated by a single space. The first integer is the number of measurements Mark took. The rest are the measured heights. Output Print to standard output (System.out) a single integer, whose value is the largest number of seconds during which Mark was continuously rising. Constraints The number of measurements is no higher than 1000. Every measurement is an integer between 0 and 1000. Example 1 Input 13 1 2 3 2 3 1 5 6 7 8 9 2 3 Output

Explanation / Answer

Basically we need to find the length of longest incresing subsequence of the array.

Java code:

LIS.java


package lis;
import java.util.Scanner;
import java.util.*;

public class LIS {


public static void main(String[] args)
{
String line;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the readings: ");
line = scanner.nextLine();
String[] parts = line.split(" ");
String ss = parts[0];
String vv = parts[1];
int readings = Integer.parseInt(ss);
int arr[] = new int[readings];
  
for(int i = 0; i<readings; i++)
{
arr[i] = Integer.parseInt(parts[i+1]);
}
int ansglob = 1;
int ans = 1;
int i = 1;
while(i < readings )
{
if(arr[i-1] < arr[i])
{
ans = ans+1;
}
else
{
ansglob = Math.max(ans,ansglob);
ans = 1;
}
i = i+1;
}
ansglob = Math.max(ans,ansglob);
System.out.println("Output = " + ansglob);
}
}

Sample Output:

1)

Enter the readings:
3 123 123 123
Output = 1

2)

Enter the readings:
13 1 2 3 2 3 1 5 6 7 8 9 2 3
Output = 6

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote