CCDSAP Preparation - Day 4

This post is again simple. I  will just add my commentaries and learnings on few of topics and related questions/problems in that topic.

Miscellaneous section: 

I wanted to add this section at the end of the post, but reality of how time went by, pushed me to place it here. Firstly, there was a weekend. And I  had already booked tickets to go for a trip. So, basically I could find very little time for myself to do some preparation. (I had planned for this trip even before registering for CCDSAP exam. My advice to future aspirants: please do not schedule any trips during your preparation days for the exam, unless and until it is very very essential. ) Moreover, on learning side, I had encountered some very good articles and videos related to blockchain and cryptocurrencies and I could not resist the temptation to read them. I also put some effort to understand merkle trees, which play a major role in blockchain database.


Continuing from last post, basically my aim was to do some actual coding against the tutorial presented in https://discuss.codechef.com/questions/87915/data-structure-tutorial-array

So, I just fired up my favorite IDE - Intellij and started coding them one by one.

Traverse code is easy and straightforward.
Insert code is not straightforward, with Java - you get ArrayIndexOutOfBoundsException, if you do not take care of indices and array length. The main trick is that, you have an array whose size is more.
Suppose you have array of size 10. Then initially add 9 elements and then write insertion code for inserting element. So, basically your array is large enough to accept the new element. This you will encounter, if you do not want to do a arraycopy, but straightforward insert of element, by shifting existing array elements to right.


  • Codechef Array Practice Problems
If you have started coding for competitive programming after a long time, you will be familiar with below experience. I opened up Intellij and started coding for LECANDY problem, the problem is straightforward, simple. I was confident enough and I submitted the solution. I got WRONG. What could go wrong. Analysed each statement. Atlast found that, in comparison, I missed <=. I had written <. Basically, edgecase. This was suggested by the editorial article. I resubmitted after making correction. Now it ran fine. I got correct answer. I was happy for a moment, because of the green output.

Then, I started working on CNOTE. This problem was also slightly easy to solve, but when I submitted the solution, I again got wrong answer. This time I was defensive against <=. But still, it was wrong. I had also tested against given testcases. But still, it was wrong. So, I read the editorial section, wherein, the author gave lot of suggestions and tips, which were very useful. One thing about performance. I had earlier chosen Scanner, because I am used to it. But Scanner's performance is very slow when you have a time limit. So, instead , I used BufferedReader. split("\\s+") -- this trick splits based on whitespace. One more thing, I was not careful about ensuring that I am reading all the testcase input data. I was breaking out of loop early, if condition was satisfied. But, we are not supposed to do so, because, it would lead to misreading of testcase inputs. Once I made all these corrections, I submitted and I was happy. It was CORRECT. Again green color.. ( I guess stackoverflow guys also show green notifications when we get upvotes ). Its part of the gamification, to engage the audience. Anyways I guess these small experiences are going to help me in the certification exam.

I am yet to attempt some more practice problems provided.




Comments

Popular posts from this blog

CCSDAP Preparation - Day 2 & 3

CCDSAP Preparation - Day1