File tree Expand file tree Collapse file tree 1 file changed +30
-7
lines changed
Most IMP Questions/Practice Expand file tree Collapse file tree 1 file changed +30
-7
lines changed Original file line number Diff line number Diff line change 17081708 },
17091709 {
17101710 "cell_type" : " markdown" ,
1711- "id" : " b49942bc " ,
1711+ "id" : " 93c30189 " ,
17121712 "metadata" : {},
17131713 "source" : [
17141714 " ## Kth Missing Positive Number [Link](https://leetcode.com/problems/kth-missing-positive-number/description/)\n " ,
17211721 },
17221722 {
17231723 "cell_type" : " markdown" ,
1724- "id" : " 59b9bfeb " ,
1724+ "id" : " 07501753 " ,
17251725 "metadata" : {},
17261726 "source" : [
17271727 " **Naive Approach 1**\n " ,
17371737 {
17381738 "cell_type" : " code" ,
17391739 "execution_count" : 5 ,
1740- "id" : " 8ea2ec69 " ,
1740+ "id" : " abc649da " ,
17411741 "metadata" : {
17421742 "ExecuteTime" : {
17431743 "end_time" : " 2024-02-06T14:50:52.949619Z" ,
17651765 },
17661766 {
17671767 "cell_type" : " markdown" ,
1768- "id" : " 2a0f72cf " ,
1768+ "id" : " c17abbb5 " ,
17691769 "metadata" : {},
17701770 "source" : [
17711771 " **Naive Approach 2**\n " ,
17751775 " <img src=\" img/KthPosInt1.png\" />\n " ,
17761776 " \n " ,
17771777 " 2. So if we get any number less than the arr[i] increment k until arr[i] > k\n " ,
1778- " 3. Return k because that is our answer"
1778+ " 3. Return k because that is our answer\n " ,
1779+ " \n " ,
1780+ " *"
17791781 ]
17801782 },
17811783 {
17821784 "cell_type" : " code" ,
17831785 "execution_count" : 6 ,
1784- "id" : " 1abf9946 " ,
1786+ "id" : " ef6b4fe3 " ,
17851787 "metadata" : {
17861788 "ExecuteTime" : {
17871789 "end_time" : " 2024-02-06T14:51:37.237858Z" ,
18071809 {
18081810 "cell_type" : " code" ,
18091811 "execution_count" : null ,
1810- "id" : " 9365306f " ,
1812+ "id" : " d0cf4542 " ,
18111813 "metadata" : {},
18121814 "outputs" : [],
18131815 "source" : []
1816+ },
1817+ {
1818+ "cell_type" : " code" ,
1819+ "execution_count" : null ,
1820+ "id" : " 634a4236" ,
1821+ "metadata" : {},
1822+ "outputs" : [],
1823+ "source" : [
1824+ " class Solution:\n " ,
1825+ " def findKthPositive(self, arr: List[int], k: int) -> int:\n " ,
1826+ " low = 0\n " ,
1827+ " high = len(arr) - 1\n " ,
1828+ " while low <= high:\n " ,
1829+ " mid = (low + high) // 2\n " ,
1830+ " missing = (arr[mid] - (mid + 1))\n " ,
1831+ " if missing < k:\n " ,
1832+ " low = mid + 1\n " ,
1833+ " else:\n " ,
1834+ " high = mid - 1\n " ,
1835+ " return high + 1 + k"
1836+ ]
18141837 }
18151838 ],
18161839 "metadata" : {
You can’t perform that action at this time.
0 commit comments