{"id":71400,"date":"2021-11-06T03:02:36","date_gmt":"2021-11-06T03:02:36","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/11\/06\/csc-python\/"},"modified":"2021-11-06T03:02:36","modified_gmt":"2021-11-06T03:02:36","slug":"csc-python","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/11\/06\/csc-python\/","title":{"rendered":"CSC python"},"content":{"rendered":"<p>Given a representation of a 2D surface (as nested list of 1\u2019s and 0\u2019s), find the area of the largest rectangle that is present on the<br \/> surface. A rectangle in this case is a m \u00d7n portion of the surface such that all positions within this portion contain a 1. In other<br \/> words, this means that the rectangle we are finding has to be a solid rectangle that is unbroken and continuous. The area of this<br \/> rectangle then, is the number of 1\u2019s that it contains (equal to m \u00d7 n). This problem by itself might be harder than it looks, so<br \/> lets first look at how we might solve a subset of the problem, as detailed in the paragraph below. <\/p>\n<p> Instead of trying to figure out what the area of the largest rectangle in the whole matrix is, we first figure out what the<br \/> area of the largest rectangle is for a given point on the matrix. This means that for a given x, y coordinate on the matrix, we<br \/> figure out the area of the largest rectangle whose top left corner starts at that point. <\/p>\n<p> Take for example this nested list: [ [1, 0, 1, 0, 0], <br \/> [1, 0, 1, 1, 1], ( to see red , green ) look at screenshot . <br \/> [1, 1, 1, 1, 1], <br \/> [ 1 , 0, 0, 1, 0]] <br \/>If we look at the position  (0 indexing), we see that there are two potential rectangles that can be formed. One length-wise<br \/> which produces a rectangle of area 5 (red), and one height-wise which produces a rectangle of area 2 (green). We want our<br \/> function for this sub-problem to return the largest of these rectangles, and so in this case it would return 5. Keep in mind that<br \/> rectangles need not be only one row or column, they could consist of multiple rows and columns, like the one you see at position<br \/>  with an area of 6 (blue), which happens to be the largest rectangle in the whole matrix. <br \/>Admittedly, this problem is harder than those seen in the previous labs, so here are some guiding points to get you started. You<br \/> must complete the tasks below in order, as each task builds on the previous one, and for each function you need to make use of<br \/> the previous one as a helper. <br \/>1. First, make sure the function longest_chain <br \/>2. Once you have completed the helper function, you can start implementing largest at position, which makes use of<br \/> longest chain. The main idea here is to loop through every row at the specified column and check how many consecutive<br \/> 1\u2019s there are on each row (beginning at that column). We suggest drawing this out on paper and coming up with a few test<br \/> cases yourself to try to visualise it. It really is quite interesting. Note: visualisation is an important tactic programmers<br \/> use to help problem solve, this is a chance for you to practice this skill! <br \/>3. While looping through the rows, you\u2019ll find that you need about three variables, one to keep track of the maximum sized<br \/> rectangle you\u2019ve seen so far, and another to keep track of the number of rows you\u2019ve seen. We\u2019ll leave the third variable for<br \/> you to figure out, but it has something to do with the longest chain function you just wrote. It\u2019s important to note that<br \/> in order for longest chain to work properly, you\u2019ll need to pass it a list that starts at the position that you are interested<br \/> in, so there\u2019s some list slicing to do on each row here. Once you have the loop set up and have all the variables updating<br \/> correctly, some simple arithmetic in every loop should be able to get you the rectangle size on each iteration. The idea<br \/> here is that for every loop, you need to calculate the largest rectangle that you can form from the part of the matrix you\u2019ve<br \/> seen so far. And the largest of these rectangles is the largest rectangle at this position. (This step is the most tricky!) <br \/>4. Finally, once largest at position is working correctly, the final function is easy to implement. Implement largest in matrix<br \/> by looping through each position in the matrix and calling largest at position. The largest rectangle in the matrix<br \/> must be the largest rectangle in all of the positions. <br \/>checking (final part) <br \/>1. written doctests and ensured that they pass? <br \/>2. considered edge cases in your doctests? <br \/> 3. run it to see if its working <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Given a representation of a 2D surface (as nested list of 1\u2019s and 0\u2019s), find the area of the largest rectangle that is present on the surface. A rectangle in this case is a m \u00d7n portion of the surface such that all positions within this portion contain a 1. In other words, this means [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[28],"class_list":["post-71400","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-computer-science"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/71400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=71400"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/71400\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=71400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=71400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=71400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}