EXPCODE1 - Editorial

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

1 Like

Hey dear, please try to fix the following-

1 . Both the links, problem and author,
lead to your profile. Also, you are
not “author” of problem, but
“editorialist”. Its best to follow
usual convention to avoid
unnecessary hassle. (I know that by
author you meant author of editorial
, but still.)

2 . Its a beginner problem, and I am sure that beginners would appreciate
if you can shed some more light on
sorting techniques. Because its
unfair that we expect beginners to
already know advanced sorting
techniques like quick sort, merge
sort etc. What I want to convey is
that, editorial should have
something/some concept for people to
learn, apart from the solution. If
you can include details of one of
the sorting techniques, the
editorial would get a lot attractive
to beginners.

3 . Stray link in line "array–a[n-1],Then answer for 2nd
Question " (last line of
explanation). Fix it by adding a
space between square brackets and
n-1.

4 . An analysis of time complexity is generally expected in editorials. See if you can do something about it :slight_smile:

done,thanks for ur suggestions,pls upvote the question if u like