{"id":1,"date":"2021-11-18T01:58:12","date_gmt":"2021-11-18T01:58:12","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/zachblog8\/?p=1"},"modified":"2021-11-18T02:18:08","modified_gmt":"2021-11-18T02:18:08","slug":"hello-world","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/zachblog8\/2021\/11\/18\/hello-world\/","title":{"rendered":"Permutation Sequence"},"content":{"rendered":"<p>So a few days ago I attempted to do Leetcode 60, permutation sequence. The problem seems simple enough, it goes something like the following. Given an integer n and an integer k, return the value of the kth permutation in the sequence of sorted permutations from [1&#8230;n]. So for example, if n and k are both equal to 3, then the sorted permutations (in ascending order) would be &#8220;123, 132, 213, 231, 312, 321&#8221;, and &#8220;213&#8221; would be returned.<\/p>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>So, for my brute force approach, I created a new array with numbers from [1&#8230;n], and then I created another method within the solution class to create all the subsets of that array, and then I returned the (k-1) element in that array as a string.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>But since this is leetcode and I wrote my solution in python, a Time Limit Exceeded error was returned. I then tried to think of a few other ways to solve this problem that could be faster, but couldn&#8217;t think of one. So I went on youtube and looked around at solution videos.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Now, I seriously hope that I never get asked this question in an interview, because the method that I saw used in the two videos I watched seemed over-the-top complicated. One of the people giving the tutorial even said it took him more than just a few hours to come up with a solution for the problem, and that it turned out to be so idiosyncratic that it can&#8217;t even really be applied to any other problem.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>I have to admit, even after studying the solution they came up with and writing it myself, I still don&#8217;t fully remember it just a few days later. Usually, when I come up with a solution on leetcode, I go back a few weeks later to questions I feel are important and retry them, and I&#8217;m able to at least get a good understanding of the approach I need to take. But with this question, I would have to repeatedly study it to remember the approach.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>That&#8217;s not to say that the provided solutions aren&#8217;t clever. They&#8217;re really, really clever. Sometimes it just seems like leetcode tries too hard to make things, well, too hard.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>So a few days ago I attempted to do Leetcode 60, permutation sequence. The problem seems simple enough, it goes something like the following. Given an integer n and an integer k, return the value of the kth permutation in the sequence of sorted permutations from [1&#8230;n]. So for example, if n and k are&hellip; <a class=\"more-link\" href=\"https:\/\/blogs.oregonstate.edu\/zachblog8\/2021\/11\/18\/hello-world\/\">Continue reading <span class=\"screen-reader-text\">Permutation Sequence<\/span><\/a><\/p>\n","protected":false},"author":11622,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/users\/11622"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/comments?post=1"}],"version-history":[{"count":2,"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":5,"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/posts\/1\/revisions\/5"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/media?parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/categories?post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/zachblog8\/wp-json\/wp\/v2\/tags?post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}