Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Write a program that finds the length of the maximal increasing sequence in an array of N integers.
- Input
- Read from the standard input
- On the first line you will receive the number N
- On the next N lines the numbers of the array will be given
- Output
- Print to the standard output
- Print the length of the maximal increasing sequence
- input 8 is the array lenght, with elements 7,3,2,3,5,2,2,4
- output is 3 - 2,3,5
- //let input = ["8", "7", "3", "2", "3", "5", "2", "2", "4"];
- //let input = ["1", "2"]; - output should be 1
- let input = ["2", "2", "1"]; - output should be 0
- let print = this.print || console.log;
- let gets =
- this.gets ||
- (
- (arr, index) => () =>
- arr[index++]
- )(input, 0);
- let arrLength = +gets();
- let previous = 0; //7//3//2//3//5//2//2//4
- let counter = 1; //1//2
- let candidateCounter = 0;
- for (let i = 0; i < arrLength; i++) {
- let element = +gets(); //3
- if (arrLength === 1) {
- candidateCounter++;
- }
- if (previous === 0) {
- previous = element;
- continue;
- }
- if (element > previous) {
- counter++;
- previous = element;
- } else {
- if (counter > 1) {
- candidateCounter = counter;
- counter = 0;
- }
- previous = element;
- }
- }
- print(candidateCounter);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement