InterviewSolution
Saved Bookmarks
| 1. |
A set of points over a straight line is defined as correlative to some K if the absolute difference between any two points ia a multiple of K |
|
Answer» def SOLVE(p,k): N = len(p) hm = dict() for t in p: if t%k in hm:hm[t%k] += 1 else:hm[t%k] = 1 rem = res = 0 for key in hm: res = max(res,hm[key]) if res == hm[key]:rem = key print(res) # printing set size # printing set elements in ascending order for t in p: if t%k == rem:print(t) return n,k = list(map(INT,(input().split()))) p = [-1 for i in range(n)] for Q in range(n): p[q] = int(input()) p.sort() solve(p,k)Explanation:All the POINTS in the set must have same remainder when divided with k. |
|