Problem: There are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given the array groupSizes of length n telling the group size each person belongs to, return the groups there are and the people’s IDs each group includes. You can return any solution in any order and the same applies for IDs. Also, it is guaranteed that there exists at least one solution. Example: Input: groupSizes = [3,3,3,3,3,1,3] Output: [[5],[0,1,2],[3,4,6]] Explanation: Other …

# Category: Python Interview Questions

Problem: Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. Each result of division is rounded to the nearest integer greater than or equal to that element. (For example: 7/3 = 3 and 10/2 = 5). It is guaranteed that there will be an answer. Example: Input: nums …

Problem: An integer has sequential digits if and only if each digit in the number is one more than the previous digit. Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits. Example: Input: low = 100, high = 300 Output: [123,234] Constraints: 10 <= low <= high <= 10^9 Solution: class Solution: def sequentialDigits(low, high): result = [] start = int(str(low)[0]) for val in range(1, len(str(low))): new_val = start%10 + 1 start = start*10 …

Problem: Given an array nums of integers, return how many of them contain an even number of digits. Example: Input: nums = [12,345,2,6,7896] Output: 2 Explanation: 12 contains 2 digits (even number of digits). 345 contains 3 digits (odd number of digits). 2 contains 1 digit (odd number of digits). 6 contains 1 digit (odd number of digits). 7896 contains 4 digits (even number of digits). Therefore only 12 and 7896 contain an even number of digits. Constraints: 1 <= …

Problem: Given an array of integers nums and a positive integer k, find whether it’s possible to divide this array into sets of k consecutive numbers. Return True if its possible otherwise return False. Example: Input: nums = [1,2,3,3,4,4,5,6], k = 4 Output: true Explanation: Array can be divided into [1,2,3,4] and [3,4,5,6]. Constraints: 1 <= nums.length <= 10^5 1 <= nums[i] <= 10^9 1 <= k <= nums.length Solution: class Solution: def isPossibleDivide(nums, k): from collections import Counter count_map = Counter(nums) for num in sorted(count_map.keys()): if count_map[num] <= …