---
description: LeetCode 668
---

# Kth Smallest Number in Multiplication Table

## 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]
```
