PROBLEM LINK-https://www.codechef.com/problems/EXPCODE1
Author:https://www.codechef.com/users/vivek96
DIFFICULTY:EASY
PREREQUISITES:Array,Sorting
PROBLEM:Being a programmer, Chef like arrays lot. On Chef’ birthday,Chef friends given him an array “a” consists of n distinct integers. Unfortunately, the size of array “a” is too small. Chef want a bigger array!,Chef friends agree to give him an bigger array.
but only if Chef is able to answer the following questions correctly:
1-Largest element in array a
2-Kth largest element
Help him for getting bigger Array!
EXPLANATION:First We need Largest Element in the Array,so we have to Sort the Array,you can use any sorting technique(bubble sort,quick sort,etc) because there is no issue of Constraints and then print the largest element in array a[[ n-1 ]]((Assuming 0 indexing and Sorting in Ascending Order)),Then answer for 2nd Question is print a[n-k],because we know the kth largest element is at position n-k
Algorithm:
begin BubbleSort(list)
for all elements of list
if list[i] greater list[i+1]
swap(list[i], list[i+1])
end if
end for
return list
end BubbleSort
Implementation: https://goo.gl/oKM4kb
AUTHOR’S AND TESTER’S SOLUTIONS:http://campus.codechef.com/EXCO17TS/viewsolution/13037182/
Edit1-Link+Corrections