[{"data":1,"prerenderedAt":330},["ShallowReactive",2],{"\u002Fblog\u002Fcode-log-day-10":3},{"id":4,"title":5,"author":6,"body":7,"date":316,"description":317,"draft":318,"extension":319,"image":320,"language":321,"meta":322,"navigation":108,"path":323,"seo":324,"stem":325,"tags":326,"__hash__":329},"blog\u002Fblog\u002FCode Log - Day 10.md","Code Log - Day 10","Caio Prado",{"type":8,"value":9,"toc":310},"minimark",[10,15,27,32,35,79,86,299,303,306],[11,12,14],"h2",{"id":13},"log","Log",[16,17,18,19,26],"p",{},"Today i solved a LeetCode exercise from the ",[20,21,25],"a",{"href":22,"rel":23},"https:\u002F\u002Fleetcode.com\u002Fstudyplan\u002Ftop-interview-150\u002F",[24],"nofollow","Top 150 Interview Questions"," list and worked on an assignment from my university.",[28,29,31],"h3",{"id":30},"leetcode","LeetCode",[16,33,34],{},"The LeetCode exercise i chose was: Remove Duplicates from Sorted Array II.\nIt requires a function that receive as input an integer array to remove in-place the numbers that already appeared more than two times and return the number of numbers left:",[36,37,38],"blockquote",{},[16,39,40,41,45,46,50,51,54,55,58,59,62,63,66,67,69,70,72,73,75,76,78],{},"Given an integer array ",[42,43,44],"code",{},"nums"," sorted in ",[47,48,49],"strong",{},"non-decreasing order",", remove some duplicates in-place such that each unique element appears ",[47,52,53],{},"at most twice",". The ",[47,56,57],{},"relative order"," of the elements should be kept the ",[47,60,61],{},"same",". ... the first ",[42,64,65],{},"k"," elements of ",[42,68,44],{}," should hold the final result. Return ",[42,71,65],{}," after placing the final result in the first ",[42,74,65],{}," slots of ",[42,77,44],{},".",[16,80,81,82,85],{},"The solution was basically the same as the ",[42,83,84],{},"Remove Duplicates from Sorted Array I",", but with a number appearance count check:",[87,88,93],"pre",{"className":89,"code":90,"language":91,"meta":92,"style":92},"language-java shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","class Solution {\n\npublic int removeDuplicates(int[] nums) {\n\n    if (\n        nums.length \u003C 1 ||\n        nums.length > 30000 ||\n        nums[0] \u003C -100 ||\n        nums[nums.length - 1] > 100\n    ) return 0;\n\n\n    \u002F\u002F starts with both idx 1 because the minimum arr.len is 1\n    \u002F\u002F and the comparison must be done using the previous number\n    int len = 1;\n    int dups = 0;\n\n    for (int i = 1; i \u003C nums.length; i++) {\n\n        \u002F\u002F compare i with i-1\n        if (nums[i] != nums[i - 1]) {\n            \u002F\u002F nums[len] is the number after the last unique number\n            nums[len] = nums[i];\n            dups = 0;\n            len++;\n        } else if(nums[i] == nums[i - 1] && dups \u003C 1){\n            nums[len] = nums[i];\n            dups++;\n            len++;\n        }\n\n    }\n    return len;\n    }\n}\n","java","",[42,94,95,103,110,116,121,127,133,139,145,151,157,162,167,173,179,185,191,196,202,207,213,219,225,231,237,243,249,254,260,265,271,276,282,288,293],{"__ignoreMap":92},[96,97,100],"span",{"class":98,"line":99},"line",1,[96,101,102],{},"class Solution {\n",[96,104,106],{"class":98,"line":105},2,[96,107,109],{"emptyLinePlaceholder":108},true,"\n",[96,111,113],{"class":98,"line":112},3,[96,114,115],{},"public int removeDuplicates(int[] nums) {\n",[96,117,119],{"class":98,"line":118},4,[96,120,109],{"emptyLinePlaceholder":108},[96,122,124],{"class":98,"line":123},5,[96,125,126],{},"    if (\n",[96,128,130],{"class":98,"line":129},6,[96,131,132],{},"        nums.length \u003C 1 ||\n",[96,134,136],{"class":98,"line":135},7,[96,137,138],{},"        nums.length > 30000 ||\n",[96,140,142],{"class":98,"line":141},8,[96,143,144],{},"        nums[0] \u003C -100 ||\n",[96,146,148],{"class":98,"line":147},9,[96,149,150],{},"        nums[nums.length - 1] > 100\n",[96,152,154],{"class":98,"line":153},10,[96,155,156],{},"    ) return 0;\n",[96,158,160],{"class":98,"line":159},11,[96,161,109],{"emptyLinePlaceholder":108},[96,163,165],{"class":98,"line":164},12,[96,166,109],{"emptyLinePlaceholder":108},[96,168,170],{"class":98,"line":169},13,[96,171,172],{},"    \u002F\u002F starts with both idx 1 because the minimum arr.len is 1\n",[96,174,176],{"class":98,"line":175},14,[96,177,178],{},"    \u002F\u002F and the comparison must be done using the previous number\n",[96,180,182],{"class":98,"line":181},15,[96,183,184],{},"    int len = 1;\n",[96,186,188],{"class":98,"line":187},16,[96,189,190],{},"    int dups = 0;\n",[96,192,194],{"class":98,"line":193},17,[96,195,109],{"emptyLinePlaceholder":108},[96,197,199],{"class":98,"line":198},18,[96,200,201],{},"    for (int i = 1; i \u003C nums.length; i++) {\n",[96,203,205],{"class":98,"line":204},19,[96,206,109],{"emptyLinePlaceholder":108},[96,208,210],{"class":98,"line":209},20,[96,211,212],{},"        \u002F\u002F compare i with i-1\n",[96,214,216],{"class":98,"line":215},21,[96,217,218],{},"        if (nums[i] != nums[i - 1]) {\n",[96,220,222],{"class":98,"line":221},22,[96,223,224],{},"            \u002F\u002F nums[len] is the number after the last unique number\n",[96,226,228],{"class":98,"line":227},23,[96,229,230],{},"            nums[len] = nums[i];\n",[96,232,234],{"class":98,"line":233},24,[96,235,236],{},"            dups = 0;\n",[96,238,240],{"class":98,"line":239},25,[96,241,242],{},"            len++;\n",[96,244,246],{"class":98,"line":245},26,[96,247,248],{},"        } else if(nums[i] == nums[i - 1] && dups \u003C 1){\n",[96,250,252],{"class":98,"line":251},27,[96,253,230],{},[96,255,257],{"class":98,"line":256},28,[96,258,259],{},"            dups++;\n",[96,261,263],{"class":98,"line":262},29,[96,264,242],{},[96,266,268],{"class":98,"line":267},30,[96,269,270],{},"        }\n",[96,272,274],{"class":98,"line":273},31,[96,275,109],{"emptyLinePlaceholder":108},[96,277,279],{"class":98,"line":278},32,[96,280,281],{},"    }\n",[96,283,285],{"class":98,"line":284},33,[96,286,287],{},"    return len;\n",[96,289,291],{"class":98,"line":290},34,[96,292,281],{},[96,294,296],{"class":98,"line":295},35,[96,297,298],{},"}\n",[28,300,302],{"id":301},"assignments","Assignments",[16,304,305],{},"I finished the assignment from the Machine Learning class, where i had to demonstrate how to make a symbolic-numeric attribute conversion with python. To be more specific, the one that was missing is the symbolic-numeric attribute using pseudo-attributes, so i made a python dictionary with an unique data combination for each author, and then i mapped these objects to the pandas data frame.",[307,308,309],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":92,"searchDepth":105,"depth":105,"links":311},[312],{"id":13,"depth":105,"text":14,"children":313},[314,315],{"id":30,"depth":112,"text":31},{"id":301,"depth":112,"text":302},"2025-01-16","Solving LeetCode's Remove Duplicates from Sorted Array II and finishing a Machine Learning assignment with pandas.",false,"md",null,"en",{},"\u002Fblog\u002Fcode-log-day-10",{"title":5,"description":317},"blog\u002FCode Log - Day 10",[327,328,30],"challenge","daily-coding","NQZH9PZQeu0jFNRNNHemdeQ4pbfreV0nmeUFy7pelrs",1785357633431]