Week 4

 In this week I try to increase the difficulty to 1200 from 900 to see what I could do. When looking at the problem the wording had me a bit confused but after a little more time I got the grasp of what they were asking. First, we take an input t, which represents how many test cases there will be. I put the number of t in a while loop so that it will run through all the test cases. A new code I learned was "while(t-->0)" this means while t is greater than zero decrement so instead of "while (t>0) and then doing t--" I do (t-->). Second, we take the number of n sticks that there will be, which I put into a for loop to go till it reaches all the sticks and create space for a set name sticks. To get to this part took me while, after trying to figure out on my own I went to YouTube to figure out how I could hold these data points and figure out what height combinations I need. That where I found that we used a data structure called a set or hashset. From the little bit I read a set is a structure that holds generic data with no duplicates. A treeset is a set that is ordered. A hashset is a set that is not ordered and is faster than the treeset. So after the video explained the problem in examples giving me a better understanding it gave me a code on how to implement the set in the solution. So after I create the set I scan for each number in the line as "a" then add a to my set and the size of the hashset is the answer ,except if it contains zero then its size minus one. With this new understanding its entirely possible that from this point that I will be taking problems and look for what data structure they can best be represented by and implementing it. With this in mind I need to learn some of the data structures before I continue up and maybe try to illustrate the problem, which I think can be really useful.  








Citations:

“Set vs Hashset VS TreeSet in Java.” Tutorials Point, https://www.tutorialspoint.com/set-vs-hashset-vs-treeset-in-java#:~:text=A%20Set%20is%20a%20generic,are%20not%20sorted%20or%20ordered.

shera522012. “A Problem on Sticks Codechef | Codechef September Long Challenge | tree2.” YouTube, YouTube, 7 Sept. 2020, https://www.youtube.com/watch?v=AlK9cfTS--w.



Comments

  1. Nice work this week on the harder problem! Keep it up.

    ReplyDelete

Post a Comment

Popular posts from this blog

Week 9

Week 10

Week 11