{"id":"8d7a805e-9d69-4f84-9412-2d809eeb439d","name":"K Largest Elements","description":"1. You will be given an Array with its length\r\n 2. You will also be given an integral value k\r\n 3. You need to find k largest elements from the given array\r\n 4. Input is handled for you\r\n 5. It is a functional problem ,please do not modify main()","inputFormat":"Input is handled for you","outputFormat":"Output MUST be in descending order","constraints":"1 &lt;= N &lt;= 100\r\n K &lt;= N\r\n -1000 &lt;= C[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include<iostream>\r\n #include<vector>\r\n #include<string>\r\n using namespace std;\r\n // -----------------------------------------------------\r\n // This is a functional problem. Only this function has to be written.\r\n // This function takes as input an array,n length of array and k.\r\n // It should print required output.\r\n void solve(int n,vector<int>& arr,int k){\r\n //Write your code here\r\n }\r\n \r\n int main(int argc,char** argv){\r\n int n;\r\n cin>>n;\r\n \r\n vector<int> v(n);\r\n for(int i=0;i<n;i++)\r\n cin>>v[i];\r\n \r\n int k;\r\n cin>>k;\r\n solve(n,v,k);\r\n }"},"java":{"code":"import java.util.*;\r\n import java.lang.*;\r\n import java.io.*;\r\n class Main\r\n {\r\n \t public static void main (String[] args) throws IOException\r\n \t {\r\n \t \t Scanner scn= new Scanner(System.in);\r\n \t \t int n = scn.nextInt();\r\n \t \t int[] num = new int[n];\r\n \t \t for (int i = 0; i < n; i++) {\r\n \t \t \t \t num[i] = scn.nextInt();\r\n \t \t \t }\r\n \t \t int k = scn.nextInt();\r\n \t \t solve(n,num,k);\r\n \t }\r\n \t // -----------------------------------------------------\r\n \t // This is a functional problem. Only this function has to be written.\r\n \t // This function takes as input an array,n length of array and k.\r\n \t // It should print required output.\r\n \t public static void solve(int n,int[] arr,int k){\r\n \t //Write your code here\r\n }\r\n }"},"python":{"code":"import sys\n\ndef kLargest(arr,size,k):\n \n # write your code here\n \n\t\t\ndef main():\n ints = []\n n = int(input())\n for i in range(0,n):\n ele=int(input())\n ints.append(ele)\n size = len(ints)\n\n k=int(input())\n kLargest(ints, size, k)\n \nif __name__ == '__main__':\n main()"}},"points":10,"difficulty":"easy","sampleInput":"8\n44 -5 -2 41 12 19 21 -6 \n2","sampleOutput":"44 41","questionVideo":null,"hints":[],"associated":[{"id":"03433abd-4018-414a-972a-a3def2d3e261","name":"What will be the output of the following input for \"K largest elements\" problem? 13 12 62 22 15 37 99 11 37 98 67 31 84 99 4","slug":"what-will-be-the-output-of-the-following-input-for-k-largest-elements-problem-13-12-62-22-15-37-99-11-37-98-67-31-84-99-4","type":4},{"id":"1d3d7081-2328-458d-9fdd-fb1736277d95","name":"What is the time complexity of \"K largest elements\" problem?","slug":"what-is-the-time-complexity-of-k-largest-elements-problem","type":4},{"id":"6de6e85b-1757-41cd-b834-b000b7d73927","name":"On what basis will the priority queue be sorted? (K largest elements)","slug":"on-what-basis-will-the-priority-queue-be-sorted-k-largest-elements","type":4},{"id":"739abc10-3f5c-4002-9dc4-12f69c0a4f42","name":"Which data structure is used in K largest elements problem?","slug":"which-data-structure-is-used-in-k-largest-elements-problem","type":4}],"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":"1254d21e-2209-40bc-9e24-00d135ace68d","name":"Hashmap And Heap For Beginners","slug":"hashmap-and-heap-for-beginners","type":0},{"id":"ed9abb3e-db1c-4726-ad84-8ce503bccdd6","name":"K Largest Elements","slug":"k-largest-elements","type":1}],"next":{"id":"cc5dd04d-e1b1-4bc7-a175-2dbea9d39014","name":"K Largest Elements","type":3,"slug":"k-largest-elements"},"prev":{"id":"1a1c5e5d-91af-4141-996d-a165980e09b9","name":"Heap - Comparable V/s Comparator","type":3,"slug":"heap-comparable-v-s-comparator"}}}

K Largest Elements

1. You will be given an Array with its length 2. You will also be given an integral value k 3. You need to find k largest elements from the given array 4. Input is handled for you 5. It is a functional problem ,please do not modify main()

{"id":"8d7a805e-9d69-4f84-9412-2d809eeb439d","name":"K Largest Elements","description":"1. You will be given an Array with its length\r\n 2. You will also be given an integral value k\r\n 3. You need to find k largest elements from the given array\r\n 4. Input is handled for you\r\n 5. It is a functional problem ,please do not modify main()","inputFormat":"Input is handled for you","outputFormat":"Output MUST be in descending order","constraints":"1 &lt;= N &lt;= 100\r\n K &lt;= N\r\n -1000 &lt;= C[i] &lt;= 1000","sampleCode":{"cpp":{"code":"#include<iostream>\r\n #include<vector>\r\n #include<string>\r\n using namespace std;\r\n // -----------------------------------------------------\r\n // This is a functional problem. Only this function has to be written.\r\n // This function takes as input an array,n length of array and k.\r\n // It should print required output.\r\n void solve(int n,vector<int>& arr,int k){\r\n //Write your code here\r\n }\r\n \r\n int main(int argc,char** argv){\r\n int n;\r\n cin>>n;\r\n \r\n vector<int> v(n);\r\n for(int i=0;i<n;i++)\r\n cin>>v[i];\r\n \r\n int k;\r\n cin>>k;\r\n solve(n,v,k);\r\n }"},"java":{"code":"import java.util.*;\r\n import java.lang.*;\r\n import java.io.*;\r\n class Main\r\n {\r\n \t public static void main (String[] args) throws IOException\r\n \t {\r\n \t \t Scanner scn= new Scanner(System.in);\r\n \t \t int n = scn.nextInt();\r\n \t \t int[] num = new int[n];\r\n \t \t for (int i = 0; i < n; i++) {\r\n \t \t \t \t num[i] = scn.nextInt();\r\n \t \t \t }\r\n \t \t int k = scn.nextInt();\r\n \t \t solve(n,num,k);\r\n \t }\r\n \t // -----------------------------------------------------\r\n \t // This is a functional problem. Only this function has to be written.\r\n \t // This function takes as input an array,n length of array and k.\r\n \t // It should print required output.\r\n \t public static void solve(int n,int[] arr,int k){\r\n \t //Write your code here\r\n }\r\n }"},"python":{"code":"import sys\n\ndef kLargest(arr,size,k):\n \n # write your code here\n \n\t\t\ndef main():\n ints = []\n n = int(input())\n for i in range(0,n):\n ele=int(input())\n ints.append(ele)\n size = len(ints)\n\n k=int(input())\n kLargest(ints, size, k)\n \nif __name__ == '__main__':\n main()"}},"points":10,"difficulty":"easy","sampleInput":"8\n44 -5 -2 41 12 19 21 -6 \n2","sampleOutput":"44 41","questionVideo":null,"hints":[],"associated":[{"id":"03433abd-4018-414a-972a-a3def2d3e261","name":"What will be the output of the following input for \"K largest elements\" problem? 13 12 62 22 15 37 99 11 37 98 67 31 84 99 4","slug":"what-will-be-the-output-of-the-following-input-for-k-largest-elements-problem-13-12-62-22-15-37-99-11-37-98-67-31-84-99-4","type":4},{"id":"1d3d7081-2328-458d-9fdd-fb1736277d95","name":"What is the time complexity of \"K largest elements\" problem?","slug":"what-is-the-time-complexity-of-k-largest-elements-problem","type":4},{"id":"6de6e85b-1757-41cd-b834-b000b7d73927","name":"On what basis will the priority queue be sorted? (K largest elements)","slug":"on-what-basis-will-the-priority-queue-be-sorted-k-largest-elements","type":4},{"id":"739abc10-3f5c-4002-9dc4-12f69c0a4f42","name":"Which data structure is used in K largest elements problem?","slug":"which-data-structure-is-used-in-k-largest-elements-problem","type":4}],"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":"1254d21e-2209-40bc-9e24-00d135ace68d","name":"Hashmap And Heap For Beginners","slug":"hashmap-and-heap-for-beginners","type":0},{"id":"ed9abb3e-db1c-4726-ad84-8ce503bccdd6","name":"K Largest Elements","slug":"k-largest-elements","type":1}],"next":{"id":"cc5dd04d-e1b1-4bc7-a175-2dbea9d39014","name":"K Largest Elements","type":3,"slug":"k-largest-elements"},"prev":{"id":"1a1c5e5d-91af-4141-996d-a165980e09b9","name":"Heap - Comparable V/s Comparator","type":3,"slug":"heap-comparable-v-s-comparator"}}}
plane

Editor


Loading...

K Largest Elements

easy

1. You will be given an Array with its length 2. You will also be given an integral value k 3. You need to find k largest elements from the given array 4. Input is handled for you 5. It is a functional problem ,please do not modify main()

Constraints

1 <= N <= 100 K <= N -1000 <= C[i] <= 1000

Format

Input

Input is handled for you

Output

Output MUST be in descending order

Example

Sample Input

8 44 -5 -2 41 12 19 21 -6 2

Sample Output

44 41

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode