> For the complete documentation index, see [llms.txt](https://zcjian.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zcjian.gitbook.io/project/mix/kth-smallest-number-in-multiplication-table.md).

# Kth Smallest Number in Multiplication Table

LeetCode 668

## Heapq \[**Time Limit Exceeded**]

```python
class Solution:
    def findKthNumber(self, m, n, k):
        """
        :type m: int
        :type n: int
        :type k: int
        :rtype: int
        """   
        nums =[]
        for i in range(1, m+1):
            for j in range(1, n+1):
                heapq.heappush(nums, i*j)  
        return heapq.nsmallest(k, nums)[-1]
```

## Heapq \[**Memory Limit Exceeded]**

```python
class Solution:
    def findKthNumber(self, m, n, k):
        """
        :type m: int
        :type n: int
        :type k: int
        :rtype: int
        """   
        nums =[i*j for i in range(1, m+1) for j in range(1, n+1)]
        heapq.heapify(nums) 
        
        return heapq.nsmallest(k, nums)[-1]
```
