{"id":"2f1c489c-0aad-4d20-96d8-1cbe54a4186e","name":"Print All Longest Increasing Subsequences","description":"1. You are given a number N representing number of elements.\r\n2. You are given N space separated numbers (ELE : elements).\r\n3. Your task is to find & print \r\n 3.1) Length of \"Longest Increasing Subsequence\"(LIS).\r\n 3.2) All \"Longest Increasing Subsequence(s)\"(LIS).\r\nNOTE: Checkout sample question/solution video inorder to have more insight.","inputFormat":"A number N (representing \"NUMBER OF ELEMENTS\").\r\nELE1 ,ELE2 ,ELE3 ,ELE4 .... ELEn (N space separated numbers represnting numbers).","outputFormat":"1) A number representing Length of \"Longest Increasing Subsequence\"(LIS).\r\n2) Strings representing \"Longest Increasing Subsequence(s)\"(LIS).\r\nCheck the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 100\r\n1 &lt;= ELE &lt;= 1000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.ArrayDeque;\r\nimport java.util.ArrayList;\r\nimport java.util.Queue;\r\nimport java.util.Scanner;\r\n\r\npublic class Main{\r\n \r\n public static class Pair {\r\n int l;\r\n int i;\r\n int v;\r\n String psf;\r\n \r\n Pair(int l, int i, int v, String psf){\r\n this.l = l;\r\n this.i = i;\r\n this.v = v;\r\n this.psf = psf;\r\n }\r\n }\r\n \r\n public static void solution(int []arr){\r\n// write your code here\r\n }\r\n \r\n \r\n \r\n public static void main(String []args){\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n = scn.nextInt();\r\n\r\n int arr[] = new int[n];\r\n for(int i = 0 ; i < n ; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n solution(arr);\r\n\r\n scn.close();\r\n }\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10\r\n10 22 9 33 21 50 41 60 80 1","sampleOutput":"6\r\n10 -> 22 -> 33 -> 41 -> 60 -> 80\r\n10 -> 22 -> 33 -> 50 -> 60 -> 80\r\n","questionVideo":"https://www.youtube.com/embed/3mD20VSib5E?end=85","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"e7bd4c93-9773-4010-8741-6013fa891431","name":"Print All Longest Increasing Subsequences","slug":"print-all-longest-increasing-subsequences","type":1}],"next":{"id":"75fdd94d-86ab-426f-a3ff-c50132971c36","name":"print all longest increasing subsequences MCQ","type":0,"slug":"print-all-longest-increasing-subsequences-mcq"},"prev":{"id":"5568f7d2-bdbc-4b42-a884-9b6fa9d78478","name":"Print All Paths With Minimum Jumps","type":3,"slug":"print-all-paths-with-minimum-jumps"}}}

Print All Longest Increasing Subsequences

1. You are given a number N representing number of elements. 2. You are given N space separated numbers (ELE : elements). 3. Your task is to find & print 3.1) Length of "Longest Increasing Subsequence"(LIS). 3.2) All "Longest Increasing Subsequence(s)"(LIS). NOTE: Checkout sample question/solution video inorder to have more insight.

{"id":"2f1c489c-0aad-4d20-96d8-1cbe54a4186e","name":"Print All Longest Increasing Subsequences","description":"1. You are given a number N representing number of elements.\r\n2. You are given N space separated numbers (ELE : elements).\r\n3. Your task is to find & print \r\n 3.1) Length of \"Longest Increasing Subsequence\"(LIS).\r\n 3.2) All \"Longest Increasing Subsequence(s)\"(LIS).\r\nNOTE: Checkout sample question/solution video inorder to have more insight.","inputFormat":"A number N (representing \"NUMBER OF ELEMENTS\").\r\nELE1 ,ELE2 ,ELE3 ,ELE4 .... ELEn (N space separated numbers represnting numbers).","outputFormat":"1) A number representing Length of \"Longest Increasing Subsequence\"(LIS).\r\n2) Strings representing \"Longest Increasing Subsequence(s)\"(LIS).\r\nCheck the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 100\r\n1 &lt;= ELE &lt;= 1000","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.util.ArrayDeque;\r\nimport java.util.ArrayList;\r\nimport java.util.Queue;\r\nimport java.util.Scanner;\r\n\r\npublic class Main{\r\n \r\n public static class Pair {\r\n int l;\r\n int i;\r\n int v;\r\n String psf;\r\n \r\n Pair(int l, int i, int v, String psf){\r\n this.l = l;\r\n this.i = i;\r\n this.v = v;\r\n this.psf = psf;\r\n }\r\n }\r\n \r\n public static void solution(int []arr){\r\n// write your code here\r\n }\r\n \r\n \r\n \r\n public static void main(String []args){\r\n Scanner scn = new Scanner(System.in);\r\n\r\n int n = scn.nextInt();\r\n\r\n int arr[] = new int[n];\r\n for(int i = 0 ; i < n ; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n\r\n solution(arr);\r\n\r\n scn.close();\r\n }\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10\r\n10 22 9 33 21 50 41 60 80 1","sampleOutput":"6\r\n10 -> 22 -> 33 -> 41 -> 60 -> 80\r\n10 -> 22 -> 33 -> 50 -> 60 -> 80\r\n","questionVideo":"https://www.youtube.com/embed/3mD20VSib5E?end=85","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"e7bd4c93-9773-4010-8741-6013fa891431","name":"Print All Longest Increasing Subsequences","slug":"print-all-longest-increasing-subsequences","type":1}],"next":{"id":"75fdd94d-86ab-426f-a3ff-c50132971c36","name":"print all longest increasing subsequences MCQ","type":0,"slug":"print-all-longest-increasing-subsequences-mcq"},"prev":{"id":"5568f7d2-bdbc-4b42-a884-9b6fa9d78478","name":"Print All Paths With Minimum Jumps","type":3,"slug":"print-all-paths-with-minimum-jumps"}}}
plane

Editor


Loading...

Print All Longest Increasing Subsequences

easy

1. You are given a number N representing number of elements. 2. You are given N space separated numbers (ELE : elements). 3. Your task is to find & print 3.1) Length of "Longest Increasing Subsequence"(LIS). 3.2) All "Longest Increasing Subsequence(s)"(LIS). NOTE: Checkout sample question/solution video inorder to have more insight.

Constraints

1 <= N <= 100 1 <= ELE <= 1000

Format

Input

A number N (representing "NUMBER OF ELEMENTS"). ELE1 ,ELE2 ,ELE3 ,ELE4 .... ELEn (N space separated numbers represnting numbers).

Output

1) A number representing Length of "Longest Increasing Subsequence"(LIS). 2) Strings representing "Longest Increasing Subsequence(s)"(LIS). Check the sample ouput and question video.

Example

Sample Input

10 10 22 9 33 21 50 41 60 80 1

Sample Output

6 10 -> 22 -> 33 -> 41 -> 60 -> 80 10 -> 22 -> 33 -> 50 -> 60 -> 80

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode