When I was extremely new to CP, I used to manually sort the arrays(by typing the whole sorting code) instead of using the Java in-built Arrays.sort(array_name) of the util package.
I would do a similar thing for binary search, until I came to know of Arrays.binarySearch(array_name,key) of the util package.
Programmers, I want to know whether there are any other such short-cut array functions, String functions, techniques,tricks, anything that you use that saves a lot of time or code writing and would help newbie coders like me as well as anyone who may not be aware of them.
You can also mentions short-cuts of other languages to help the users coding in them.
I remember something similar happening with me too.
I was participating in a contest, and the problem included sorting the array and doing some operations, and I was getting TLE because of my slow sorting algoâŚand in the editorial I saw that âArrays.sortâ function and I was like âWTF?!â
Its good to inquire and know about these things.
However, I am afraid that the list is toooo long to be stated here. Hence I would request you to go through string fucntions list For others, please refer to meowâs answer, nothing that I give could be more detailed than that! . Pay special attention to array and string methods, they are what mostly save your life. (Array.push, pop and sort should be known at least. They are quite useful!)
If, after seeing the list, you have any query/doubt/need clarification, feel free to ask here again.
The best place to find convenient in-built functions is of course the language documentation. Here are Javadoc links for the Arrays and String class. You will find all the available functions listed along with their purpose, parameters, and return value. Go through them and take note of what may be useful to you.
Since you are new you wouldnât be requiring these at the moment, but in the future you will likely have to use a Collection. Some useful Collections are ArrayList, ArrayDeque, PriorityQueue, HashSet and TreeSet. HashMap and TreeMap are also useful. StringBuilder is another useful class. If all these seem too overwhelming, donât worry, you donât need these right now. The Java library is pretty big
On the plus side, because it is so big, it will often have something that matches a functionality you are looking for. Hope this helps!
I agree. Whats worse is that if you use these stuff in school papers, they give zero citing âOut of Syllabusâ thing. Thatâs sad, but I hope you enjoy the time you spend on Computer Science and Coding
Thatâs true. Yup, I love Computer Science and Maths. Coding and algorithms fascinate me a lot. Competetive Programming has that thrill factor- especially short contests. They are fast and thrilling. Often itâs nail-biting, when only 5-10 minutes are left and you are trying your best to get your solution accepted. Long contests teach us a lot
Yes!! BTW, CS and Maths? Youâre gonna go far kid :D. Knowing maths is a good advantage in CS.
Yes short contests are thrilling, and long contests are very, very good for knowledge.
I still remember how anxious I was during last minutes when I scored my final 15 marks (partial marking) out of 50 marked Q, earning a silver medal (hackerrank contest give medals based on ranking. Top 12 % get medal, and by those 15 marks I slipped into that :p)
I am happy you got your passion clear at this age dear! It took me 2 years to find I love CS and coding.
Haha, you praise too much. Whatâs the thing about passions? A person may have a liking today which may seem like a passion, but may change tomorrow. Passions often deceive
But yeah, Iâve really liked Computer Science since class 8 and Maths since long back. Iâm currently a class 11 Science student and the thing that distinguishes Maths and CS from Chem and Physics is the number of âAHA!â and âWOW!â moments it gives- you know, when you have been thinking about a problem for a long time, staring at it, and then, suddenly, you get the solution! Such moments are pricelessâŚ
Passions which are deceptive are not passions, they are just âlikingâ. Its important to differentiate between a âlikingâ and a âpassionâ. And yes, CS has a LOT of wow moments XD
If you are new in competitive programming then i suggest you to switch your java to C++ language as C++ is best and best among all other languages specially in Competitive programming. You can estimate this by looking submission of languages at any platform like codechef, SPOJ, Hackerearth, COdeforces etc. Even one of the top programmer Gennady Korotkevich also used C++ as a special tool In programming.
You canât forget Petr and uwi. It isnât bad to use Java either. All that matters is your hold on Algorithms and Data Structures. And the functions that are listed below are available in Java too. Please donât misguide people or build such stereotypes that C++ is better than Java in competitive programming. There are perks of using Java in comparison to C++.
Exactly. Most sites like Codechef focus on the algorithmic complexity as much as possible by allowing many languages and setting appropriate relative time limits. It is not necessary to learn a completely new language for competitive programming. Choice of language should be upto the programmer.