By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,496 Members | 1,527 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,496 IT Pros & Developers. It's quick & easy.

Python to c conversion. Pls do convert this code to c language

P: 1
Expand|Select|Wrap|Line Numbers
  1. from collections import deque, Counter
  2.  
  3. class Solution:
  4.     def smallestRange(self, nums: List[List[int]]) -> List[int]:
  5.  
  6.         new = []
  7.         # merge each list and keep track of original list
  8.         for i in range(len(nums)):
  9.             for j in nums[i]:
  10.                 new.append((j, i))
  11.         # sort so each sliding window represents a range
  12.         new.sort()
  13.  
  14.         d = deque()
  15.         c = Counter()
  16.  
  17.         res = [-float('inf'), float('inf')]
  18.         # iterate over sliding windows that contain each list
  19.         for i in new:
  20.             d.append(i)
  21.             c[i[1]] += 1
  22.             while len(c) == len(nums):
  23.                 res = min(res, [d[0][0], d[-1][0]], key = lambda x: x[1] - x[0])
  24.                 a, b = d.popleft()
  25.                 c[b] -= 1
  26.                 if not c[b]: del c[b]
  27.         return res
Oct 20 '19 #1
Share this Question
Share on Google+
1 Reply


100+
P: 144
Please do have a look on posting guidelines.
Oct 20 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.